NdArray::shape

Tuple of array dimensions.

Description

array NdArray::shape

Return Values

A 1-dim array

Examples

Example #1: Get the NdArray shape

use SciPhp\NumPhp as np;

$m = np::linspace(1, 9, 9)->reshape(3, 3);

$shape = np::ar($m->shape);

echo 
"m\n$m", "shape=$shape\n";

The above example will output:

m
[[1  2  3]
 [4  5  6]
 [7  8  9]]
shape=[3  3]

Example #2: Reshape an NdArray

use SciPhp\NumPhp as np;

$m = np::ar([1, 2, 3, 4]);

$m->shape = [2, 2];

echo 
"m\n$m";

The above example will output:

m
[[1  2]
 [3  4]]

See Also