Construct a new array of a given value with the same shape and type as a given array.
SciPhp\NdArray
NumPhp::full_like(
array|NdArray
$array
,
float|int
$value
)
$array
$value
Although is is not recommanded, it is possible to specify an array.
The new SciPhp\NdArray
use SciPhp\NumPhp as np;
$x = np::full_like(
[[2, 2],
[2, 2]], 42
);
echo $x;
The above example will output:
[[42 42] [42 42]]
use SciPhp\NumPhp as np;
// 3-D array
$input = np::linspace(1, 8, 8)->reshape(2, 2, 2);
$x = np::full_like($input, 42);
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]]]