numpy重塑具有特定顺序的数组 [英] Numpy reshape an array with specific order
本文介绍了numpy重塑具有特定顺序的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有这个数组x:
x = array([1, 2, 3, 4, 5, 6, 7, 8])
x.shape = (8,1)
我想重塑它成为
array([[1, 3, 5, 7],
[2, 4, 6, 8]])
这是在x上的reshape(2,4),但是很简单:
this is a reshape(2, 4) on x but in the straight forward way:
y = x.reshape(2,4)
y变为
array([[1, 2, 3, 4],
[5, 6, 7, 8]])
那不是我想要的.有没有办法以这种特定方式转换数组?
and that's not what I want. Is there a way to transform the array in that specific way?
推荐答案
In[4]: x.reshape(4, 2).T
Out[4]:
array([[1, 3, 5, 7],
[2, 4, 6, 8]])
这篇关于numpy重塑具有特定顺序的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文