python reshape order_python – order =’F’的numpy.reshape()如何工作?

‘F’的元素

array([[ 0, 1, 2, 3],

[ 4, 5, 6, 7],

[ 8, 9, 10, 11],

[12, 13, 14, 15]])

是[0,4,8,12,1,5,9 …]

现在用(2,8)数组重新排列它们.

我认为重塑文档谈论了对元素的粗暴,然后重新塑造它们.显然,首先完成了ravel.

尝试a.ravel(order =’F’).重塑(2,8).

哎呀,我得到了你的期望:

In [208]: a = np.arange(16).reshape(4,4)

In [209]: a

Out[209]:

array([[ 0, 1, 2, 3],

[ 4, 5, 6, 7],

[ 8, 9, 10, 11],

[12, 13, 14, 15]])

In [210]: a.ravel(order='F')

Out[210]: array([ 0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15])

In [211]: _.reshape(2,8)

Out[211]:

array([[ 0, 4, 8, 12, 1, 5, 9, 13],

[ 2, 6, 10, 14, 3, 7, 11, 15]])

好的,我必须在重塑期间保持’F’顺序

In [214]: a.ravel(order='F').reshape(2,8, order='F')

Out[214]:

array([[ 0, 8, 1, 9, 2, 10, 3, 11],

[ 4, 12, 5, 13, 6, 14, 7, 15]])

In [215]: a.ravel(order='F').reshape(2,8).flags

Out[215]:

C_CONTIGUOUS : True

F_CONTIGUOUS : False

...

In [216]: a.ravel(order='F').reshape(2,8, order='F').flags

Out[216]:

C_CONTIGUOUS : False

F_CONTIGUOUS : True

来自np.reshape docs

You can think of reshaping as first raveling the array (using the given

index order), then inserting the elements from the raveled array into the

new array using the same kind of index ordering as was used for the

raveling.

订单上的注释相当长,所以这个主题令人困惑也就不足为奇了.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值