Write a NumPy program to multiply an array of dimension (2,2,3) by an array with dimensions (2,2).
import numpy as np nums1 = np.ones((2,2,3)) nums2 = 3*np.ones((2,2)) print("Original array:") print(nums1) new_array = nums1 * nums2[:,:,None] print("\nNew array:") print(new_array)
Sample Output:
Original array: [[[1. 1. 1.] [1. 1. 1.]] [[1. 1. 1.] [1. 1. 1.]]] New array: [[[3. 3. 3.] [3. 3. 3.]] [[3. 3. 3.] [3. 3. 3.]]]
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