热线电话:13121318867

登录
2020-09-13 阅读量: 975
reshape参数中的-1的理解

感觉写作-1怪怪的,其实它表示任何的意思。

1.当原始数组A[4,6]为二维数组,代表4行6列。

A.reshape(-1,8):表示将数组转换成8列的数组,具体多少行我们不知道,所以参数设为-1。用我们的数学可以计算出是3行8列

2.当原始数组A[4,6]为二维数组,代表4行6列。

A.reshape(3,-1):表示将数组转换成3行的数组,具体多少列我们不知道,所以参数设为-1。用我们的数学可以计算出是3行8列


"""

import numpy as np

a=np.arange(24)

print(a)

b=a.reshape(3,-1)

print(b)

c=a.reshape(-1,8)

print(c)


d=a.reshape(2,3,2,2)

print(d)


66.4083
0
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子