Getting error: Cannot reshape array of size 122304 into shape (52,28,28)

后端 未结 2 1277
半阙折子戏
半阙折子戏 2021-01-18 02:08

I\'m trying to reshape a numpy array as:

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

where data3 is:

[[54          


        
相关标签:
2条回答
  • 2021-01-18 02:10

    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)
    

    Output is of the form

    [[[     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]]]
    
    0 讨论(0)
  • 2021-01-18 02:31

    First, your input image's number of elements should match the number of elements in the desired feature vector.

    Assuming the above is satisfied, the below should work:

    # Reading all the images to a one numpy array. Paths of the images are in the imagePaths
    data = np.array([np.array(cv2.imread(imagePaths[i])) for i in range(len(imagePaths))])
    
    # This will contain the an array of feature vectors of the images
    features = data.flatten().reshape(1, 784)
    
    0 讨论(0)
提交回复
热议问题