Q:

Write a NumPy program to divide each row by a vector element

0

Write a NumPy program to divide each row by a vector element.

All Answers

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

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

 

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