python中的广播

向量(列): a = (1,2,3) 

a + 100 --广播 -> (a + (100, 100, 100))  -->  (101,102,103)

[[1,2,3],            +    (100,200,300)  ==  (101,102,103)

[4,5,6]]                                                  (104,205,306)

 

c = np.array([[1,2,3]])
# print(c.shape) #(1, 3)

b = np.array([[4,5,6]])
b = b.T #(3, 1)
# print(b.shape)#(3, 1)

print(c + b)

[[5 6 7]
 [6 7 8]
 [7 8 9]]

 

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(-5, 5, 0.1)
y = np.arange(-5, 5, 0.1)
xx, yy = np.meshgrid(x, y, sparse=True)

a = (xx**2 + yy**2)
b = np.sin(xx**2 + yy**2)
z = np.sin(xx**2 + yy**2) / (xx**2 + yy**2)
h = plt.contourf(x ,y ,z)


plt.show()

python中的广播