Write a NumPy program to divide each row by a vector element.
import numpy as np x = np.array([[20,20,20],[30,30,30],[40,40,40]]) print("Original array:") print(x) v = np.array([20,30,40]) print("Vector:") print(v) print(x / v[:,None])
Sample Output:
Original array: [[20 20 20] [30 30 30] [40 40 40]] Vector: [20 30 40] [[ 1. 1. 1.] [ 1. 1. 1.] [ 1. 1. 1.]]
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: