Python Forum
cannot reshape array of size 0 into shape
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cannot reshape array of size 0 into shape
After a correction on the program i am using, i get an error on my code :
import numpy as np
import gzip
import struct

def load_images(filename):
    # Open and unzip the file of images :
    with, 'rb') as f:
        # read the header, information into a bunch of variables:
        _ignored, n_images, image_columns, image_rows = struct.unpack('>IIII', bytearray([:16]))
        print(_ignored, n_images, image_columns, image_rows)
        # read all the pixels into a long numpy array :
        all_pixels = np.frombuffer(, dtype=np.uint8)
        # reshape the array into a matrix where each line is an image:
        images_matrix = all_pixels.reshape(n_images, image_columns * image_rows)
load_images("\\MNIST\\train-images-idx3-ubyte.gz") 2051 60000 28 28 b'' [] (0,) 1 Traceback (most recent call last): File "<input>", line 1, in <module> File "<input>", line 19, in load_images ValueError: cannot reshape array of size 0 into shape (60000,784)
I tried to defined the array, but still not working....
you try to use several times.
After first use, you are at the end of the file.
As you can see from there on when you try to print on line 12 you get b'', also on line 15 you get [], shape is `(0,) and so on..
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Thanks, I've added

and it seems OK.

Possibly Related Threads…
Thread Author Replies Views Last Post
  [pandas] How to reshape the list Mekala 6 1,177 Jul-26-2020, 12:49 AM
Last Post: Mekala
  Python changed array shape without telling me BrendanGolledge 3 727 Jun-11-2020, 07:41 AM
Last Post: Yoriz
  Bad input shape for SVC Scott 1 2,417 Dec-07-2019, 08:03 AM
Last Post: scidam
  reshape from 3D to 3D matrix paul18fr 0 632 Nov-12-2019, 11:26 AM
Last Post: paul18fr
  Simple numpy reshape error wih contour3D AdeIsHere 0 762 Sep-17-2019, 12:01 PM
Last Post: AdeIsHere
  How to get the size of a numpy array? mcgrim 2 1,353 Mar-23-2019, 02:25 PM
Last Post: perfringo
  ValueError: could not broadcast input array from shape (75) into shape (25) route2sabya 0 4,271 Mar-14-2019, 01:14 PM
Last Post: route2sabya
  'list' object has no attribute 'reshape' SamSoftwareLtd 1 10,147 Nov-04-2018, 10:38 PM
Last Post: stullis
  python odeint keeps giving me size of array error kiyoshi7 1 2,561 Nov-01-2018, 02:03 AM
Last Post: j.crater
  The size of the array returned by func (1) does not match usmankhan 0 2,756 Jan-16-2018, 12:27 PM
Last Post: usmankhan

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020