Sum along diagonals.
float|int
NdArray::trace(
int
$k = 0
)
$k
A float|int
use SciPhp\NumPhp as np;
$m = np::arange(0, 9)->reshape(3, 3);
$r = $m->trace();
echo "m\n$m", "r\n$r";
The above example will output:
m [[0 1 2] [3 4 5] [6 7 8]] r 12
use SciPhp\NumPhp as np;
$m = np::arange(0, 9)->reshape(3, 3);
$r = $m->trace(1);
echo "m\n$m", "r\n$r";
The above example will output:
m [[0 1 2] [3 4 5] [6 7 8]] r 6