classnumpy.broadcast(*arrays)
Produce an object that mimics broadcasting.
Parameters:in1, in2, …array_likeInput parameters.
Attributes:
current index in broadcasted result
tuple of iterators along self’s “components.”
Number of dimensions of broadcasted result.
Number of dimensions of broadcasted result.
Number of iterators possessed by the broadcasted result.
Shape of broadcasted result.
Total size of broadcasted result.
Methods
Returns:bbroadcast objectBroadcast the input parameters against one another, and return an object that encapsulates the result. Amongst others, it has shape and nd properties, and may be used as an iterator.
Examples
Manually adding two vectors, using broadcasting:
>>> importnumpyasnp>>> x=np.array([[1],[2],[3]])>>> y=np.array([4,5,6])>>> b=np.broadcast(x,y)>>> out=np.empty(b.shape)>>> out.flat=[u+vfor(u,v)inb]>>> outarray([[5., 6., 7.], [6., 7., 8.], [7., 8., 9.]])Compare against built-in broadcasting:
>>> x+yarray([[5, 6, 7], [6, 7, 8], [7, 8, 9]])