NumPhp::ones

Create a new NdArray filled with ones

Description

SciPhp\NdArray NumPhp::ones( mixed $tuple )

Parameters

$tuple
This parameter can be an array [1, 2, 3] or a tuple of integers (1, 2, 3).

Return Values

The new SciPhp\NdArray

Examples

Example #1: Creating a new NdArray based on a shape

use SciPhp\NumPhp as np;

$x np::ones([22]);

echo 
$x;

The above example will output:

[[1  1]
 [1  1]]

Example #2: Creating a new NdArray based on a tuple

use SciPhp\NumPhp as np;

$x np::ones(333);

echo 
$x;

The above example will output:

[[[1  1  1]
  [1  1  1]
  [1  1  1]]
 [[1  1  1]
  [1  1  1]
  [1  1  1]]
 [[1  1  1]
  [1  1  1]
  [1  1  1]]]

See Also