- class numpy.broadcast[source]¶
Produce an object that mimics broadcasting.
in1, in2, ... : array_like
b : broadcast object
Broadcast 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.
Manually adding two vectors, using broadcasting:
>>> x = np.array([, , ]) >>> y = np.array([4, 5, 6]) >>> b = np.broadcast(x, y)
>>> out = np.empty(b.shape) >>> out.flat = [u+v for (u,v) in b] >>> out array([[ 5., 6., 7.], [ 6., 7., 8.], [ 7., 8., 9.]])
Compare against built-in broadcasting:
>>> x + y array([[5, 6, 7], [6, 7, 8], [7, 8, 9]])
index current index in broadcasted result iters tuple of iterators along self‘s “components.” shape Shape of broadcasted result. size Total size of broadcasted result.
next x.next() -> the next value, or raise StopIteration reset() Reset the broadcasted result’s iterator(s).