flopscope.numpy.broadcast_arrays
fnp.broadcast_arrays(*args, subok=False)[flopscope source][numpy source]
Broadcast any number of arrays against each other.
Adapted from NumPy docs np.broadcast_arrays
Broadcast arrays against each other. Cost: numel(output).
Parameters
- *args:array_likes
The arrays to broadcast.
- subok:bool, optional
If True, then sub-classes will be passed-through, otherwise the returned arrays will be forced to be a base-class array (default).
Returns
- broadcasted:tuple of arrays
These arrays are views on the original arrays. They are typically not contiguous. Furthermore, more than one element of a broadcasted array may refer to a single memory location. If you need to write to the arrays, make copies first. While you can set the
writableflag True, writing to a single output value may end up changing more than one location in the output array.Deprecated since 1.17.
See also
Examples
>>> import flopscope.numpy as fnp
>>> x = flops.array([[1,2,3]])
>>> y = flops.array([[4],[5]])
>>> flops.broadcast_arrays(x, y)
(array([[1, 2, 3],
[1, 2, 3]]),
array([[4, 4, 4],
[5, 5, 5]]))Here is a useful idiom for getting contiguous copies instead of non-contiguous views.
>>> [flops.array(a) for a in flops.broadcast_arrays(x, y)]
[array([[1, 2, 3],
[1, 2, 3]]),
array([[4, 4, 4],
[5, 5, 5]])]