NdArray::ndim

Number of dimensions of an array.

Description

int NdArray::ndim

Return Values

A positive integer.

Examples

Example #1: Get the number of dimensions

use SciPhp\NumPhp as np;

$m np::linspace(199)->reshape(33);

$dim $m->ndim;

echo 
"m\n$m""m->ndim=$dim\n";

The above example will output:

m
[[1  2  3]
 [4  5  6]
 [7  8  9]]
m->ndim=2

Example #2: Changing the number of dimensions

use SciPhp\NumPhp as np;

$m np::ar([123]);

// Transforming a line vector into a column vector
$n $m->resize(31);

echo 
"m (ndim={$m->ndim})\n{$m}""\nn (ndim={$n->ndim})\n{$n}";

The above example will output:

m (ndim=1)
[1  2  3]

n (ndim=2)
[[1]
 [2]
 [3]]

See Also