Q:

Write a NumPy program to multiply an array of dimension (2,2,3) by an array with dimensions (2,2)

0

Write a NumPy program to multiply an array of dimension (2,2,3) by an array with dimensions (2,2).

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.]]]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now