reshape()函数

"""

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)

参考:https://www.jianshu.com/p/04a408c3528b

原文地址:https://www.cnblogs.com/yibeimingyue/p/11422099.html