如何从numpy中的D数组制作一个D维坐标数组

how to make an array of D-dimensional coordinates from D arrays in numpy

在 numpy 中,我有 D 个数组,每个数组的长度为 n,我想从这些数组生成一个长度为 n 的 D 维坐标数组。然后,每个数组提供一个坐标轴的值。

例如,在二维空间中:

import numpy as np
x = np.arange(5)
y = x + 4

#from which I would like to make this nd.array:
[[0, 4],
 [1, 5],
 [2, 6],
 [3, 7],
 [4, 8]]

您可以使用 column_stack:

>>> np.column_stack((x, y))
array([[0, 4],
       [1, 5],
       [2, 6],
       [3, 7],
       [4, 8]])

column_stack接受一个数组序列,所以如果你有D个数组你想堆叠,你可以直接用D调用column_stack