flopscope.numpy.broadcast_to
fnp.broadcast_to(array, shape, subok=False)[flopscope source][numpy source]
Broadcast an array to a new shape.
Adapted from NumPy docs np.broadcast_to
Cost
0
Flopscope Context
Broadcast array to new shape. Cost: numel(output).
Parameters
- array:array_like
The array to broadcast.
- shape:tuple or int
The shape of the desired array. A single integer
iis interpreted as(i,).- subok:bool, optional
If True, then sub-classes will be passed-through, otherwise the returned array will be forced to be a base-class array (default).
Returns
- broadcast:array
A readonly view on the original array with the given shape. It is typically not contiguous. Furthermore, more than one element of a broadcasted array may refer to a single memory location.
Raises
- :ValueError
If the array is not compatible with the new shape according to NumPy's broadcasting rules.
See also
Examples
>>> import flopscope.numpy as fnp
>>> x = flops.array([1, 2, 3])
>>> flops.broadcast_to(x, (3, 3))
array([[1, 2, 3],
[1, 2, 3],
[1, 2, 3]])