numpy.broadcast_to#
- numpy.broadcast_to(array,shape,subok=False)[source]#
Broadcast an array to a new shape.
- Parameters:
- arrayarray_like
The array to broadcast.
- shapetuple or int
The shape of the desired array. A single integer
iis interpretedas(i,).- subokbool, optional
If True, then sub-classes will be passed-through, otherwisethe returned array will be forced to be a base-class array (default).
- Returns:
- broadcastarray
A readonly view on the original array with the given shape. It istypically not contiguous. Furthermore, more than one element of abroadcasted array may refer to a single memory location.
- Raises:
- ValueError
If the array is not compatible with the new shape according to NumPy’sbroadcasting rules.
Examples
>>>importnumpyasnp>>>x=np.array([1,2,3])>>>np.broadcast_to(x,(3,3))array([[1, 2, 3], [1, 2, 3], [1, 2, 3]])
On this page