Python reshape()函数用法
reshape(行数,列数)用于更改数组的行列数
a = np.array([[1,2,3],[4,5,6]])
print(a.shape)
>>>(2,3)
b = a. reshape(6,1)
c = a. reshape(3,-1)
d = a. reshape(-1,3)
print('b:',b, '\nc:',c, '\nd:',d)
>>>b: [[1]
[2]
[3]
[4]
[5]
[6]]
c: [[1,2]
[3,4]
[5,6]]
d: [[1,2,3]
[4,5,6]]
📎当行数或列数为-1时,Numpy会根据剩下的维度计算出-1的值。适合数据较多或偷懒时用。