且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

出现错误:无法将大小为122304的数组重塑为形状(52,28,28)

更新时间:2023-09-17 13:34:22

您可以调整numpy矩阵数组的形状,使before(a x b x c..n)= after(a x b x c..n).即矩阵中的总元素应与以前相同,在您的情况下,您可以对其进行转换,以使转换后的数据3 形状为(156,28,28)或简单地:-

You can reshape the numpy matrix arrays such that before(a x b x c..n) = after(a x b x c..n). i.e the total elements in the matrix should be same as before, In your case, you can transform it such that transformed data3 has shape (156, 28, 28) or simply :-

import numpy as np

data3 = np.arange(122304).reshape(52, 2352 )

data3 = data3.reshape((data3.shape[0]*3, 28, 28))

print(data3.shape)

输出格式为

[[[     0      1      2 ...,     25     26     27]
  [    28     29     30 ...,     53     54     55]
  [    56     57     58 ...,     81     82     83]
  ..., 
  [   700    701    702 ...,    725    726    727]
  [   728    729    730 ...,    753    754    755]
  [   756    757    758 ...,    781    782    783]]
  ...,
[122248 122249 122250 ..., 122273 122274 122275]
  [122276 122277 122278 ..., 122301 122302 122303]]]