numpy中meshgrid函数接收两个一维数组,并产生两个二维矩阵
import numpy as np
points=np.arange(-5,5,0.01) #生成1000个间隔相等的点
xs,ys=np.meshgrid(points,points)
ys
import matplotlib.pyplot as plt
z=np.sqrt(xs**2+ys**2)
z
plt.imshow(z,cmap=plt.cm.gray);plt.colorbar();plt.title('image plot of $\sqrt{x^2+y^2}$ for a grid of values')
array([[-5. , -5. , -5. , ..., -5. , -5. , -5. ],
[-4.99, -4.99, -4.99, ..., -4.99, -4.99, -4.99],
[-4.98, -4.98, -4.98, ..., -4.98, -4.98, -4.98],
...,
[ 4.97, 4.97, 4.97, ..., 4.97, 4.97, 4.97],
[ 4.98, 4.98, 4.98, ..., 4.98, 4.98, 4.98],
[ 4.99, 4.99, 4.99, ..., 4.99, 4.99, 4.99]])import matplotlib.pyplot as plt
z=np.sqrt(xs**2+ys**2)
z
Out[43]: