Sum along diagonals.
float|int
NumPhp::trace(
array|NdArray
$m
,
int
$k = 0
)
$m
$k
A float|int
use SciPhp\NumPhp as np;
$m = np::arange(0, 9)->reshape(3, 3);
$r = np::trace($m);
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 = np::trace($m, 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