我有
x=np.array([[1,2,3],[3,4,5],[5,7,8]])
y=np.array([[5,2,5],[1,1,1],[2,2,2]])
我想
xy=[(1,5),(2,2),(3,5),(3,1),(4,1),(5,1),(5,2),(7,2),(8,2)]
最好(快速和干净)的方式是什么?另外,一旦我xy
,我如何将xy
的索引与原始的numpy矩阵x
,y
相关联?
答案 0 :(得分:2)
您可以使用此方法获取xy
:
zip(x.flatten(),y.flatten())
#[(1, 5), (2, 2), (3, 5), (3, 1), (4, 1), (5, 1), (5, 2), (7, 2), (8, 2)]
答案 1 :(得分:1)
您可以尝试:
>>> x = [[1,2,3],[3,4,5],[5,7,8]]
>>> y = [[5,2,5],[1,1,1],[2,2,2]]
>>> x1 = [val for x_data in x for val in x_data]
>>> y1 = [val for y_data in y for val in y_data]
>>> final = [(a,b) for a, b in zip(x1, y1)]
>>> print final
[(1, 5), (2, 2), (3, 5), (3, 1), (4, 1), (5, 1), (5, 2), (7, 2), (8, 2)]
答案 2 :(得分:0)
转置或使用Toast.makeText(getBaseContext(), "User's location retrieved using library for android M in btnRetryGpsEvents()", Toast.LENGTH_SHORT).show();
:
nop.dstack()