Python Numpy数组转换

Python Numpy数组转换,python,numpy,Python,Numpy,我有两个numpy数组x1和x2。使用python 3.4.3 x1 = np.array([2,4,4]) x2 = np.array([3,5,3]) 我想要一个这样的numpy阵列: [[2,3],[4,5],[4,3]] x3 = list(zip(x1,x2)) 我该怎么办呢?是的。听起来像是zip函数: import numpy as np x1 = np.array([2,4,4]) x2 = np.array([3,5,3]) print zip(x1, x2) #

我有两个numpy数组x1和x2。使用python 3.4.3

x1 = np.array([2,4,4])
x2 = np.array([3,5,3])
我想要一个这样的numpy阵列:

[[2,3],[4,5],[4,3]]
x3 = list(zip(x1,x2))

我该怎么办呢?

是的。听起来像是zip函数:

import numpy as np 

x1 = np.array([2,4,4])
x2 = np.array([3,5,3])

print zip(x1, x2) # or [list(i) for i in zip(x1, x2)]
您可以使用:


您可以
zip
2个数组,如下所示:

[[2,3],[4,5],[4,3]]
x3 = list(zip(x1,x2))
输出:

[(2, 3), (4, 5), (4, 3)]
[[2, 3], [4, 5], [4, 3]]
上面的代码创建了
元组的
列表
。如果您想要
列表的
列表
,可以使用
列表理解

x3 = [list(i) for i in list(zip(x1,x2))]
输出:

[(2, 3), (4, 5), (4, 3)]
[[2, 3], [4, 5], [4, 3]]

OP特别要求输出为numpyarray@mtrw这是OP发布为所需输出的内容:
[[2,3],[4,5],[4,3]]
。是的,我知道他称之为numpy数组…OP特别要求输出为numpyarray@mtrw是的!你说得对。沃伦的答案是最好的解决方案。非常好!Numpy内置解决方案。我不知道,谢谢你!,这太完美了