如何通过 Python 中的 X、Y 坐标创建点矩阵?

How to create matrix of points by X, Y coordinate in Python?

我有: X 最小值、Y 最小值和 X 最大值、Y 最大值。 需要创建此边界内点之间距离为 2000.0 米的点的网格。

我的代码:

while minY < maxY:
    minY += 2000.0
        while minX < maxX:
            minX += 2000.0
            X.append(minX)
            Y.append(minY)
     X.append(minX)
     Y.append(minY)

给我:1 行 X(从最小值到最大值)和 1 个点的冒号 Y()从 Xmax - 最后一个 X.

请帮我创建点行/网格。

我怀疑这段代码可以满足您的需要。但是,您可能需要阅读一些基本的 python 教程 (https://docs.python.org/2/tutorial/) 来帮助您入门。

import numpy as np
# define the lower and upper limits for x and y
minX, maxX, minY, maxY = 0., 20000., 10000., 50000.
# create one-dimensional arrays for x and y
x = np.linspace(minX, maxX, (maxX-minX)/2000.+1)
y = np.linspace(minY, maxY, (maxY-minY)/2000.+1)
# create the mesh based on these arrays
X, Y = np.meshgrid(x, y)

如果您需要网格在一维数组中,您可以重新整形它们:

X = X.reshape((np.prod(X.shape),))
Y = Y.reshape((np.prod(Y.shape),))

然后您可以轻松地将它们压缩到

coords = zip(X, Y)