Broadcast an array to a new shape.
SciPhp\NdArray
NumPhp::broadcast_to(
array|NdArray
$m
,
array
$shape
)
$m
$shape
A new SciPhp\NdArray
use SciPhp\NumPhp as np;
$x = np::broadcast_to([1, 2, 3], [1, 3]);
echo $x;
The above example will output:
x [[1 2 3]]
use SciPhp\NumPhp as np;
$x = np::broadcast_to([1, 2, 3], [3, 3]);
echo "x\n$x";
The above example will output:
x [[1 2 3] [1 2 3] [1 2 3]]
use SciPhp\NumPhp as np;
$x = np::broadcast_to(
[[1],
[2],
[3]],
[3, 3]
);
echo "x\n$x";
The above example will output:
x [[1 1 1] [2 2 2] [3 3 3]]
use SciPhp\NumPhp as np;
$x = np::broadcast_to([1, 2, 3], [3, 1]);
The above example will output:
InvalidArgumentException: Arrays could not be broadcast together with remapped shapes [original->remapped]: [3] and requested shape [3 1]