NumPhp::full_like

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

Description

SciPhp\NdArray NumPhp::full_like( array|NdArray $array , float|int $value )

Parameters

$array
An array [1, 2, 3] or a NdArray.
$value
A float or an integer.

Although is is not recommanded, it is possible to specify an array.

Return Values

The new SciPhp\NdArray

Examples

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

use SciPhp\NumPhp as np;

$x np::full_like(
  [[
22],
   [
22]], 42
);

echo 
$x;

The above example will output:

[[42  42]
 [42  42]]

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

use SciPhp\NumPhp as np;

// 3-D array 
$input np::linspace(188)->reshape(222);

$x np::full_like($input42);

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

The above example will output:

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

Output:
[[[42  42]
  [42  42]]
 [[42  42]
  [42  42]]]

See Also