以自定义方式重塑python numpy数组

时间:2016-10-24 13:54:17

标签: python arrays numpy

我有这样一个python numpy数组;

[[-0.17433028 -0.20116786 -0.17599097 -0.1907735   0.27599955 -0.16071874]
 [-0.21809219 -0.20256139 -0.15900832 -0.18323743 -0.26910328  0.78731642]]

如何将数组重塑为以下内容?

[[-0.17433028, -0.21809219], [-0.20116786, -0.20256139], [-0.17599097, -0.15900832], [-0.1907735, -0.18323743], [0.27599955, -0.26910328], [-0.16071874, 0.78731642]]

2 个答案:

答案 0 :(得分:3)

您想使用transpose方法:

>>> arr = np.array([[-0.17433028, -0.20116786, -0.17599097, -0.1907735, 0.27599955, -0.16071874], [-0.21809219, -0.20256139, -0.15900832, -0.18323743, -0.26910328,  0.78731642]])

>>> arr.transpose()
array([[-0.17433028, -0.21809219],
       [-0.20116786, -0.20256139],
       [-0.17599097, -0.15900832],
       [-0.1907735 , -0.18323743],
       [ 0.27599955, -0.26910328],
       [-0.16071874,  0.78731642]])

答案 1 :(得分:1)

这看起来像你想要矩阵的转置。您可以使用numpy.transpose(array)执行此操作。