Number of dimensions of an array.
int
NdArray::ndim
A positive integer.
use SciPhp\NumPhp as np;
$m = np::linspace(1, 9, 9)->reshape(3, 3);
$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
use SciPhp\NumPhp as np;
$m = np::ar([1, 2, 3]);
// Transforming a line vector into a column vector
$n = $m->resize(3, 1);
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]]