NumPy Array manipulation: broadcast_arrays() function

numpy.broadcast_arrays() function

The broadcast_arrays() function broadcasts any number of arrays against each other.


numpy.broadcast_arrays(*args, **kwargs)
NumPy manipulation: broadcast_arrays() function

Version: 1.15.0


Name Description Required /
*args The arrays to broadcast. Required
subok If True, then sub-classes will be passed-through, otherwise the returned arrays will be forced to be a base-class array (default). Optional

Return value:

broadcasted [list 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.

Example: numpy.broadcast_arrays()

>>> import numpy as np
>>> a = np.array([[2,3,4]])
>>> b = np.array([[2],[3],[4]])
>>> np.broadcast_arrays(a, b)
[array([[2, 3, 4],
       [2, 3, 4],
       [2, 3, 4]]), array([[2, 2, 2],
       [3, 3, 3],
       [4, 4, 4]])]

Pictorial Presentation:

NumPy manipulation: broadcast-arrays() function

Python - NumPy Code Editor:

Previous: broadcast_to()
Next: expand_dims()