NumPhp::transpose

Permute the dimensions of an array.

Description

SciPhp\NdArray NumPhp::transpose( array|NdArray $m , array $axes )

Parameters

$m
An array [1, 2, 3] or a NdArray.
$axes
A 1-dim array which represents axes.

Return Values

The new SciPhp\NdArray

Examples

Example #1: Transpose a 1-dim array

use SciPhp\NumPhp as np;

$x np::transpose([123]);

print 
$x;

The above example will output:

[1  2  3]

Example #2: Transpose a 2-dim array

use SciPhp\NumPhp as np;

$x np::linspace(166)->reshape(23);
$xT np::transpose($x);

echo 
"x\n$x""xT\n$xT";

The above example will output:

x
[[1  2  3]
 [4  5  6]]
xT
[[1  4]
 [2  5]
 [3  6]]

See Also