MCordingley\LinearAlgebra\Matrix::transpose PHP Метод

transpose() публичный Метод

public transpose ( ) : self
Результат self
    public function transpose() : self
    {
        $literal = [];
        for ($i = 0, $columns = $this->getColumnCount(); $i < $columns; $i++) {
            $literal[] = [];
            for ($j = 0, $rows = $this->getRowCount(); $j < $rows; $j++) {
                $literal[$i][] = $this->get($j, $i);
            }
        }
        return new static($literal);
    }

Usage Example

Пример #1
0
 public function regress(array $dependentData, array $independentData)
 {
     $design = new Matrix($independentData);
     $observed = (new Matrix([$dependentData]))->transpose();
     if ($design->columns >= $design->rows) {
         throw new InvalidArgumentException('Not enough observations to perform regression. You need to have more observations than explanatory variables.');
     }
     $designTranspose = $design->transpose();
     $prediction = $designTranspose->multiply($design)->inverse()->multiply($designTranspose->multiply($observed));
     // Extract the vertical vector as a simple array.
     return $prediction->transpose()->toArray()[0];
 }
All Usage Examples Of MCordingley\LinearAlgebra\Matrix::transpose