我有跟随2D numpy数组的列X和Y
[(476301.98163511883, 6178749.129456658)
(477927.0510582989, 6178741.4760845825)
(477918.79328165855, 6177112.834659822)]
[(476301.98163511883, 6175045.129456658)
(477927.0510582989, 6175037.4760845825)
(477918.79328165855, 6173408.834659822)]
我正在尝试将两者合并在一起,同时保留行顺序
结果如下所示:
[(476301.98163511883, 6178749.129456658), (476301.98163511883, 6175045.129456658)
(477927.0510582989, 6178741.4760845825), (477927.0510582989, 6175037.4760845825)
(477918.79328165855, 6177112.834659822), (477918.79328165855, 6173408.834659822)]
我目前使用这样的生成器工作,但我觉得这是 NOT 正确的方法。
def generator_array():
for value in both_arrays:
yield value
x = generator_array()
feature_list = []
try:
while x:
pt1 = next(x)
pt2 = next(x)
feature_list.append((pt1[0], pt1[1], pt2[0], pt2[1]))
except StopIteration:
pass
由于
答案 0 :(得分:0)
我不太确定你问的是什么,因为你的代码没有产生你想要的结果,但会:
np.hstack((a,b))
工作,a
和b
是哪两个数组?
答案 1 :(得分:0)
concatenate
可行:
a=np.array([(476301.98163511883, 6178749.129456658), (477927.0510582989, 6178741.4760845825), (477918.79328165855, 6177112.834659822)])
b=np.array([(476301.98163511883, 6175045.129456658), (477927.0510582989, 6175037.4760845825), (477918.79328165855, 6173408.834659822)])
np.concatenate((a,b),axis=1)
array([[ 476301.98163512, 6178749.12945666, 476301.98163512,
6175045.12945666],
[ 477927.0510583 , 6178741.47608458, 477927.0510583 ,
6175037.47608458],
[ 477918.79328166, 6177112.83465982, 477918.79328166,
6173408.83465982]])
答案 2 :(得分:0)
我可以通过以下方式让它工作
import numpy.lib.recfunctions as rfn
merged_array = rfn.merge_arrays((array1,array2), usemask = False)