NumPhp::ar

Construct a new N-dimensional array

Description

SciPhp\NdArray NumPhp::ar( array $data )

NumPhp::ar() is an alias of NumPy.array() in Python.

Parameters

$data
A multidimensional array of data.

Return Values

The new SciPhp\NdArray

Examples

Example #1: Creating an array of rank 1 - A point or a vector

use SciPhp\NumPhp as np;

// x, y, z coordinates
$x np::ar([123]);

echo 
$x;

The above example will output:

[1  2  3]

Example #2: Creating an array of rank 2 - A matrix

use SciPhp\NumPhp as np;

$x np::ar([[12], [34]]);

echo 
$x;

The above example will output:

[[1  2]
 [3  4]]

See Also