Construct a 2-D array with ones on the diagonal and zeros elsewhere.
SciPhp\NdArray
NumPhp::eye(
int
$rows
[,
int
$cols = 0
]
[,
int
$k = 0
])
$rows
$cols
$k
use SciPhp\NumPhp as np;
$m = np::eye(4);
print $m;
The above example will output:
[[1 0 0 0] [0 1 0 0] [0 0 1 0] [0 0 0 1]]
use SciPhp\NumPhp as np;
$m = np::eye(3, 5);
print $m;
The above example will output:
[[1 0 0 0 0] [0 1 0 0 0] [0 0 1 0 0]]
use SciPhp\NumPhp as np;
$m = np::eye(3, 5, 2);
print $m;
The above example will output:
[[0 0 1 0 0] [0 0 0 1 0] [0 0 0 0 1]]