How do you build row and column coordinate grids?
meshgrid expands coordinate vectors into coordinate grids. Matrix indexing preserves the order of the input axes.
numpy.meshgrid in practice
For a two-by-three image each row of the column grid reads 0,1,2. Match the indexing convention to pixel access when connecting the grid to a plot.
import numpy as np
np.meshgrid([0,1],[0,1,2], indexing='ij')[1]Result [[0, 1, 2], [0, 1, 2]]
中文
怎样为图像每个像素生成行列坐标?
meshgrid 把每条轴的一维坐标扩展为坐标网格。ij 约定保留输入轴的次序。
numpy.meshgrid 算例
两行三列的图像中,列坐标网格的两行都是 0、1、2。改变索引约定会改变轴顺序,绘图时要与像素访问方式一致。
import numpy as np
np.meshgrid([0,1],[0,1,2], indexing='ij')[1]结果 [[0, 1, 2], [0, 1, 2]]