NumPhp::nulls_like

Construct a new array of nulls with the same shape and type as a given array.

Description

SciPhp\NdArray NumPhp::nulls_like( array|NdArray $array )

It is equivalent to the np.empty_like() for NumPy

Parameters

$array
An array [1, 2, 3] or a NdArray.

Return Values

The new SciPhp\NdArray

Examples

Example #1: Constructing an array of nulls with array as input

use SciPhp\NumPhp as np;

$x = np::nulls_like(
  [[
2, 2],
   [
2, 2]]
);

echo 
$x;

The above example will output:

[[null  null]
 [null  null]]

Example #2: Constructing an array of nulls with N-dim array as input

use SciPhp\NumPhp as np;

// 3-D array 
$input = np::linspace(1, 8, 8)->reshape(2, 2, 2);

$x = np::nulls_like($input);

echo 
"
Input:
$input
Output:
$x
"
;

The above example will output:

Input:
[[[1  2]
  [3  4]]
 [[5  6]
  [7  8]]]

Output:
[[[null  null]
  [null  null]]
 [[null  null]
  [null  null]]]

See Also