【发布时间】:2022-01-21 14:38:35
【问题描述】:
我有一个充满值的 numpy 二维数组 (50x50)。我想将二维数组展平为一列(2500x1),但这些值的位置非常重要。索引可以转换为空间坐标,所以我想要另外两个 (x,y) (2500x1) 数组,这样我就可以检索相应值的 x,y 空间坐标。
例如:
My 2D array:
--------x-------
[[0.5 0.1 0. 0.] |
[0. 0. 0.2 0.8] y
[0. 0. 0. 0. ]] |
My desired output:
#Values
[[0.5]
[0.1]
[0. ]
[0. ]
[0. ]
[0. ]
[0. ]
[0.2]
...],
#Corresponding x index, where I will retrieve the x spatial coordinate from
[[0]
[1]
[2]
[3]
[4]
[0]
[1]
[2]
...],
#Corresponding y index, where I will retrieve the x spatial coordinate from
[[0]
[0]
[0]
[0]
[1]
[1]
[1]
[1]
...],
关于如何做到这一点的任何线索?我已经尝试了一些方法,但没有奏效。
【问题讨论】: