Broadcasting in NumPy


 #Broadcasting
import numpy as np
# We will add,multiply, subtract  the vector v to each row of the matrix x,
x = np.array([[1,2,3], [4,5,6], [7,8,9]])
v = np.array([1, 0, 1])
print(x)
print(v)                 
y = x + v
y1= x * v
y2= x - v
print("Addition\n",y,"\n","Multiplication \n",y1,"\n","Subtraction \n",y2) 

No comments: