结合使用Python和numpy的数组 [英] Combining an array using Python and NumPy

查看:141
本文介绍了结合使用Python和numpy的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有形式的两个数组:

  A = np.array([1,2,3])
B = np.array([4,5,6])

有没有我可以应用到这些阵列以获得followng输出numpy的功能?

  [1,4],[2,5] [3,6]


解决方案

  np.vstack((A,B)):T

返回

 阵列([1,4]
       [2,5]
       [3,6]])

  np.vstack((A,B))。T.tolist()

返回正是你需要的:

  [[1,4],[2,5],[3,6]

I have two arrays of the form:

a = np.array([1,2,3])
b = np.array([4,5,6])

Is there a NumPy function which I can apply to these arrays to get the followng output?

[[1,4],[2,5][3,6]]

解决方案

np.vstack((a,b)).T

returns

array([[1, 4],
       [2, 5],
       [3, 6]])

and

np.vstack((a,b)).T.tolist()

returns exactly what you need:

[[1, 4], [2, 5], [3, 6]]

这篇关于结合使用Python和numpy的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆