Phpml\Math\Matrix::crossOut PHP Method

crossOut() public method

public crossOut ( integer $row, integer $column ) : Matrix
$row integer
$column integer
return Matrix
    public function crossOut(int $row, int $column)
    {
        $newMatrix = [];
        $r = 0;
        for ($i = 0; $i < $this->rows; ++$i) {
            $c = 0;
            if ($row != $i) {
                for ($j = 0; $j < $this->columns; ++$j) {
                    if ($column != $j) {
                        $newMatrix[$r][$c] = $this->matrix[$i][$j];
                        ++$c;
                    }
                }
                ++$r;
            }
        }
        return new self($newMatrix, false);
    }

Usage Example

Exemplo n.º 1
0
 public function testCrossOutMatrix()
 {
     $matrix = new Matrix([[3, 4, 2], [4, 5, 5], [1, 1, 1]]);
     $crossOuted = [[3, 2], [1, 1]];
     $this->assertEquals($crossOuted, $matrix->crossOut(1, 1)->toArray());
 }