Return the transpose of this matrix

@param Matrix $matrix The matrix whose transpose we wish to calculate
@return Matrix
@throws Exception
172290
public static function transpose(Matrix $matrix)
    {
        $grid = call_user_func_array(
            'array_map',
            array_merge(
                [null],
                $matrix->toArray()
            )
        );

        return new Matrix($grid);
    }
675014
public function multiply($b)
    {
        switch (true) {
            case $b instanceof Vector:
                $c = $this->multiplyVector($b);
                break;

            case $b instanceof Matrix:
                $c = $this->multiplyMatrix($b);
                break;

            case is_int($b) or is_float($b):
                $c = $this->multiplyScalar($b);
                break;

            default:
                throw new InvalidArgumentException('Cannot multiply vector'
                    . ' with a ' . gettype($b) . '.');
        }

        return $c;
    }
1060089
public function result() : Matrix
    {
        if (!$this->result) {
            $this->result = call_user_func($this->computation);
        }

        return $this->result;
    }
55080
public function add($b)
    {
        switch (true) {
            case $b instanceof Matrix:
                $c = $this->addMatrix($b);
                break;

            case $b instanceof ColumnVector:
                $c = $this->addColumnVector($b);
                break;
            
            case $b instanceof Vector:
                $c = $this->addVector($b);
                break;

            case is_int($b) or is_float($b):
                $c = $this->addScalar($b);
                break;

            default:
                throw new InvalidArgumentException('Cannot add matrix'
                    . ' to a ' . gettype($b) . '.');
        }

        return $c;
    }
1146624
public IMatrix transpose() {
        IMatrix result = new IMatrix(rows, columns);
        transpose(result);
        return result;
    }
1005046
public function transpose() : self
    {
        if ($this->m > 1) {
            $b = array_map(null, ...$this->a);
        } else {
            $b = [];

            for ($i = 0; $i < $this->n; $i++) {
                $b[] = array_column($this->a, $i);
            }
        }

        return self::quick($b);
    }
155603
@Override
    public DoubleMatrix transpose()
    {
        int m = rows();
        int n = columns();
        ItemSupplier s = supplier;
        DoubleMatrix tr = getInstance(n, m);
        ItemConsumer c = tr.consumer;
        for (int i = 0; i < m; i++)
        {
            for (int j = 0; j < n; j++)
            {
                c.set(j, i, s.get(i, j));
            }
        }
        return tr;
    }
327977
protected static function getMinors(Matrix $matrix)
    {
        $minors = $matrix->toArray();
        $dimensions = $matrix->rows;
        if ($dimensions == 1) {
            return $minors;
        }

        for ($i = 0; $i < $dimensions; ++$i) {
            for ($j = 0; $j < $dimensions; ++$j) {
                $minors[$i][$j] = self::getDeterminantSegment($matrix, $i, $j);
            }
        }

        return $minors;
    }
1021354
public static void transpose( DMatrix3x3 m ) {
        double tmp;
        tmp = m.a12; m.a12 = m.a21; m.a21 = tmp;
        tmp = m.a13; m.a13 = m.a31; m.a31 = tmp;
        tmp = m.a23; m.a23 = m.a32; m.a32 = tmp;
    }
710346
protected function doTransform(Matrix $mA, $extra = null)
    {
        if ($mA->is('empty')) {
            return new Matrix([]);
        }
        /** @noinspection PhpInternalEntityUsedInspection */
        $this->assertParameterIsArray($extra, 'Second operand is not an array');

        if (count($extra) != 2) {
            throw new MatrixException('Second operand does not contain row and column');
        }
        $row = intval($extra[0]);
        $col = intval($extra[1]);
        $size = $mA->rows();
        if ($row<1 || $row > $size) {
            throw new MatrixException('Row indicator out of bounds');
        }
        if ($col<1 || $col > $size) {
            throw new MatrixException('Col indicator out of bounds');
        }

        $fC = new Colreduce();
        $fR = new Rowreduce();
        //R(C(mA))
        return $fR($fC($mA,[$col]),[$row]);
    }
1197690
public function getMatrix()
    {
        if (func_num_args() > 0) {
            $args = func_get_args();
            $match = implode(',', array_map('gettype', $args));
            switch ($match) {
 
      //A($i0...; $j0...)
      case 'integer,integer':
        list($i0, $j0) = $args;
          $m = $i0 >= 0 ? $this->m - $i0 : trigger_error(ArgumentBoundsException, ERROR);
          $n = $j0 >= 0 ? $this->n - $j0 : trigger_error(ArgumentBoundsException, ERROR);
          $R = new Matrix($m, $n);
 
          for ($i = $i0; $i < $this->m; $i++) {
              for ($j = $j0; $j < $this->n; $j++) {
                  $R->set($i, $j, $this->A[$i][$j]);
              }
          }
 
          return $R;
          break;
 
      //A($i0...$iF; $j0...$jF)
      case 'integer,integer,integer,integer':
       list($i0, $iF, $j0, $jF) = $args;
        $m = (($iF > $i0) && ($this->m >= $iF) && ($i0 >= 0)) ? $iF - $i0 : trigger_error(ArgumentBoundsException, ERROR);
        $n = (($jF > $j0) && ($this->n >= $jF) && ($j0 >= 0)) ? $jF - $j0 : trigger_error(ArgumentBoundsException, ERROR);
        $R = new Matrix($m+1, $n+1);
 
        for ($i = $i0; $i <= $iF; $i++) {
            for ($j = $j0; $j <= $jF; $j++) {
                $R->set($i - $i0, $j - $j0, $this->A[$i][$j]);
            }
        }
 
        return $R;
        break;
 
      //$R = array of row indices; $C = array of column indices
      case 'array,array':
        list($RL, $CL) = $args;
        $m = count($RL) > 0 ? count($RL) : trigger_error(ArgumentBoundsException, ERROR);
        $n = count($CL) > 0 ? count($CL) : trigger_error(ArgumentBoundsException, ERROR);
        $R = new Matrix($m, $n);
 
        for ($i = 0; $i < $m; $i++) {
            for ($j = 0; $j < $n; $j++) {
                $R->set($i - $i0, $j - $j0, $this->A[$RL[$i]][$CL[$j]]);
            }
        }
 
        return $R;
        break;
 
      //$RL = array of row indices; $CL = array of column indices
      case 'array,array':
        list($RL, $CL) = $args;
        $m = count($RL) > 0 ? count($RL) : trigger_error(ArgumentBoundsException, ERROR);
        $n = count($CL) > 0 ? count($CL) : trigger_error(ArgumentBoundsException, ERROR);
        $R = new Matrix($m, $n);
 
        for ($i = 0; $i < $m; $i++) {
            for ($j = 0; $j < $n; $j++) {
                $R->set($i, $j, $this->A[$RL[$i]][$CL[$j]]);
            }
        }
 
        return $R;
        break;
 
      //A($i0...$iF); $CL = array of column indices
      case 'integer,integer,array':
        list($i0, $iF, $CL) = $args;
        $m = (($iF > $i0) && ($this->m >= $iF) && ($i0 >= 0)) ? $iF - $i0 : trigger_error(ArgumentBoundsException, ERROR);
        $n = count($CL) > 0 ? count($CL) : trigger_error(ArgumentBoundsException, ERROR);
        $R = new Matrix($m, $n);
 
        for ($i = $i0; $i < $iF; $i++) {
            for ($j = 0; $j < $n; $j++) {
                $R->set($i - $i0, $j, $this->A[$RL[$i]][$j]);
            }
        }
 
        return $R;
        break;
 
      //$RL = array of row indices
      case 'array,integer,integer':
        list($RL, $j0, $jF) = $args;
        $m = count($RL) > 0 ? count($RL) : trigger_error(ArgumentBoundsException, ERROR);
        $n = (($jF >= $j0) && ($this->n >= $jF) && ($j0 >= 0)) ? $jF - $j0 : trigger_error(ArgumentBoundsException, ERROR);
        $R = new Matrix($m, $n+1);
 
        for ($i = 0; $i < $m; $i++) {
            for ($j = $j0; $j <= $jF; $j++) {
                $R->set($i, $j - $j0, $this->A[$RL[$i]][$j]);
            }
        }
 
        return $R;
        break;
      default:
        trigger_error(PolymorphicArgumentException, ERROR);
        break;
      }
        } else {
            trigger_error(PolymorphicArgumentException, ERROR);
        }
    }
679998
public function subtract($b)
    {
        switch (true) {
            case $b instanceof Matrix:
                $c = $this->subtractMatrix($b);
                break;

            case $b instanceof ColumnVector:
                $c = $this->subtractColumnVector($b);
                break;
                
            case $b instanceof Vector:
                $c = $this->subtractVector($b);
                break;

            case is_int($b) or is_float($b):
                $c = $this->subtractScalar($b);
                break;

            default:
                throw new InvalidArgumentException('Cannot subtract a '
                    . gettype($b) . ' from a matrix.');
        }

        return $c;
    }
60985
public static function calculateDeterminant($matrix) : float {
        // The ´rows´ args is the only needed one. Determinants can only be calculated
        // from a square matrix. Hence we use the row as size for both row and column.
        $determinant = 0;
        $rcCount     = count($matrix);
        if ($rcCount !== count($matrix[0])) {
            throw new InvalidArgumentException(
                "Can only calculate determinant from square matrix (same amount of rows as columns)."
            );
        }

        // If only one element, return the value from it.
        if ($rcCount === 1) {
            return $matrix[0][0];
        }

        $sign = 1;
        // Go through each element in first row.
        for ($counter=0;$counter<$rcCount;$counter++) {
            // Create a cofactor sub-matrix ($rcCount-1 in size).
            $subMatrix = self::getSubMatrix($matrix, 0, $counter);
            // Calculate the determinant of the sub-matrix.
            $determinant += $sign * $matrix[0][$counter] * self::calculateDeterminant($subMatrix);
            $sign         = -$sign;
        }

        return $determinant;
    }
638240
public function transpose() {
        $cpy = new static();
        $cpy->copy($this);

        for ($i=0; $i<static::ROWS; $i++) {
            for ($j=0; $j<static::COLUMNS; $j++) {
                $this[$i][$j] = $cpy[$j][$i];
            }
        }

    }
612862
public function getD()
    {
        for ($i = 0; $i < $this->n; ++$i) {
            $D[$i] = array_fill(0, $this->n, 0.0);
            $D[$i][$i] = $this->d[$i];
            if ($this->e[$i] == 0) {
                continue;
            }
            $o = ($this->e[$i] > 0) ? $i + 1 : $i - 1;
            $D[$i][$o] = $this->e[$i];
        }
        return new Matrix($D);
    }
1216686
function transpose(matrix) {
                var resultMatrix = new Array(matrix[0].length);
                for (var i = 0; i < resultMatrix.length; ++i) {
                    resultMatrix[i] = new Array(matrix.length);
                }

                for (i = 0; i < matrix.length; ++i) {
                    for (var j = 0; j < matrix[0].length; ++j) {
                        resultMatrix[j][i] = matrix[i][j];
                    }
                }

                return resultMatrix;
            }
997960
public function multiply(Matrix $matrix)
    {
        if ($this->columns != $matrix->getRows()) {
            throw InvalidArgumentException::inconsistentMatrixSupplied();
        }

        $product = [];
        $multiplier = $matrix->toArray();
        for ($i = 0; $i < $this->rows; ++$i) {
            $columns = $matrix->getColumns();
            for ($j = 0; $j < $columns; ++$j) {
                $product[$i][$j] = 0;
                for ($k = 0; $k < $this->columns; ++$k) {
                    $product[$i][$j] += $this->matrix[$i][$k] * $multiplier[$k][$j];
                }
            }
        }

        return new self($product, false);
    }