简体   繁体   English

被numpy meshgrid输出混淆

[英]confused by numpy meshgrid output

Using Python 2.7 with miniconda interpreter. 将Python 2.7与miniconda解释器一起使用。 I am confused by what means ND coordinate in the following statements, and could anyone tell how in the below sample xv and yv are calculated, it will be great. 我对以下语句中ND坐标的含义感到困惑,谁能说出下面的示例xvyv的计算方式,那就太好了。

"Make ND coordinate arrays for vectorized evaluations of ND scalar/vector fields over ND grids, given one-dimensional coordinate arrays x1, x2,..., xn." “给定一维坐标数组x1,x2,...,xn,使ND坐标数组用于ND网格上ND标量/矢量场的矢量化评估。”

http://docs.scipy.org/doc/numpy/reference/generated/numpy.meshgrid.html http://docs.scipy.org/doc/numpy/reference/generation/numpy.meshgrid.html

>>> nx, ny = (3, 2)
>>> x = np.linspace(0, 1, nx)
>>> y = np.linspace(0, 1, ny)
>>> xv, yv = meshgrid(x, y)
>>> xv
array([[ 0. ,  0.5,  1. ],
       [ 0. ,  0.5,  1. ]])
>>> yv
array([[ 0.,  0.,  0.],
       [ 1.,  1.,  1.]])

regards, Lin 问候,林

xv,yv are simply defined as: xv,yv简单定义为:

xv = np.array([x for _ in y])
yv = np.array([y for _ in x]).T

so that for every index pair (i,j) , you have 这样,对于每个索引对(i,j)

xv[i,j] = x[i]
yv[i,j] = y[j]

which is useful especially for plotting 2D maps. 这在绘制2D地图时特别有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM