numpy-meshgrid函数理解

经常遇到np.meshgrid,但是一直没太能理解

该函数输入一些一维向量x1,x2,…,xn
返回X1,X2,…,Xn,它们形状为(len(x1),len(x2),…,len(xn)),在index='ij’的情况下
In the 2-D case with inputs of length M and N, the outputs are of shape (N, M) for ‘xy’ indexing and (M, N) for ‘ij’ indexing. In the 3-D case with inputs of length M, N and P, outputs are of shape (N, M, P) for ‘xy’ indexing and (M, N, P) for ‘ij’ indexing.
在2D和3D的情况下稍有不同
X1,X2…,Xn的元素只与对应的xi有关,只是在哪个维度填充有讲究

For vectors x1, x2,…, ‘xn’ with lengths Ni=len(xi) , return (N1, N2, N3,…Nn) shaped arrays if indexing=’ij’ or (N2, N1, N3,…Nn) shaped arrays if indexing=’xy’ with the elements of xi repeated to fill the matrix along the first dimension for x1, the second for x2 and so on.
官方解释,返回的向量shape,向量的内容要用原始向量来填补,则先在对于维度先拷贝一份原始数组,其它维度都是该数组的重复

你可能感兴趣的:(numpy)