NumPhp::identity

Construct a square 2-D array with ones on the diagonal and zeros elsewhere.

Description

SciPhp\NdArray NumPhp::identity( int $side )

Parameters

$side
A positive integer. Represents number of rows.

Return Values

A SciPhp\NdArray

Examples

Example #1: Constructing a 4x4 identity matrix

use SciPhp\NumPhp as np;

$m np::identity(4);

print 
$m;

The above example will output:

[[1  0  0  0]
 [0  1  0  0]
 [0  0  1  0]
 [0  0  0  1]]

See Also