NumPy: Broadcast on different shapes of arrays where a(,3) + b(3)
NumPy: Array Object Exercise-125 with Solution
Write a NumPy program to broadcast on different shapes of arrays where a(,3) + b(3).
The a variable has a shape of (, 3), while b only has a shape of 3.
import numpy as np p = np.array([, , ]) q= np.array([10, 11, 12]) print("Original arrays:") print("Array-1") print(p) print("Array-2") print(q) print("\nNew Array:") new_array1 = p + q print(new_array1)
Original arrays: Array-1 [[ 0]  ] Array-2 [10 11 12] New Array: [[10 11 12] [20 21 22] [30 31 32]]
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Python skills with w3resource's quiz
Python: Tips of the Day
>>> m = [x ** 2 for x in range(5)] >>> m [0, 1, 4, 9, 16]
- New Content published on w3resource:
- 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