NumPy: broadcast() function
numpy.broadcast() function
The broadcast() function produces an object that mimics broadcasting.
Syntax:
class numpy.broadcast
Version: 1.15.0
Parameter:
Name | Description | Required / Optional |
---|---|---|
in1, in2, . . . | Input parameters. | Required |
Return value:
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.
Example-1: numpy.broadcast()
>>> import numpy as np
>>> a = np.array([[2], [3], [4]])
>>> b = np.array([5, 6, 7])
>>> z = np.broadcast(a, b)
>>> y = np.empty(z.shape)
>>> y.flat = [u+v for (u,v) in z]
>>> y
array([[ 7., 8., 9.],
[ 8., 9., 10.],
[ 9., 10., 11.]])
Example-2: numpy.broadcast()
>>> import numpy as np
>>> a = np.array([[2], [3], [4]])
>>> b = np.array([5, 6, 7])
>>> a+b
array([[ 7, 8, 9],
[ 8, 9, 10],
[ 9, 10, 11]])
Pictorial Presentation:
Python - NumPy Code Editor:
Previous: atleast_3d()
Next: broadcast_to()
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework