Write a NumPy program to broadcast on different shapes of arrays where p(3,3) + q(3).
The p variable has a shape of (3, 3), while q only has a shape of 3.
import numpy as np p = np.array([[0, 0, 0], [1, 2, 3], [4, 5, 6]]) 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)
Sample Output:
Original arrays: Array-1 [[0 0 0] [1 2 3] [4 5 6]] Array-2 [10 11 12] New Array: [[10 11 12] [11 13 15] [14 16 18]]
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer