Phpml\Math\Matrix::fromFlatArray PHP Method

fromFlatArray() public static method

public static fromFlatArray ( array $array ) : Matrix
$array array
return Matrix
    public static function fromFlatArray(array $array)
    {
        $matrix = [];
        foreach ($array as $value) {
            $matrix[] = [$value];
        }
        return new self($matrix);
    }

Usage Example

Exemplo n.º 1
0
 public function testCreateMatrixFromFlatArray()
 {
     $flatArray = [1, 2, 3, 4];
     $matrix = Matrix::fromFlatArray($flatArray);
     $this->assertInstanceOf(Matrix::class, $matrix);
     $this->assertEquals([[1], [2], [3], [4]], $matrix->toArray());
     $this->assertEquals(4, $matrix->getRows());
     $this->assertEquals(1, $matrix->getColumns());
     $this->assertEquals($flatArray, $matrix->getColumnValues(0));
 }
All Usage Examples Of Phpml\Math\Matrix::fromFlatArray