I know this question has been asked before but I can't seem to get mine to work.
import numpy as np def load_dataset(): def download(filename, source="http://yaan.lecun.com/exdb/mnist/"): print ("Downloading ",filename) import urllib urllib.urlretrieve(source+filename,filename) import gzip def load_mnist_images(filename): if not os.path.exists(filename): download(filename) with gzip.open(filename,"rb") as f: data=np.frombuffer(f.read(), np.uint8, offset=16) data = data.reshape(-1,1,28,28) return data/np.float32(256) def load_mnist_labels(filename): if not os.path.exists(filename): download(filename) with gzip.open(filename,"rb") as f: data = np.frombuffer(f.read(), np.uint8, offset=8) return data X_train = load_mnist_images("train-images-idx3-ubyte.gz") y_train = load_mnist_labels("train-labels-idx1-ubyte.gz") X_test = load_mnist_images("t10k-images-idx3-ubyte.gz") y_test = load_mnist_labels("t10k-labels-idx1-ubyte.gz") return X_train, y_train, X_test, y_test X_train, y_train, X_test, y_test = load_dataset() import matplotlib matplotlib.use("TkAgg") import matplotlib.pyplot as plt plt.show(plt.imshow(X_train[3][0]))
This is the error I am getting:
Traceback (most recent call last): File "C:\Users\nehad\Desktop\Neha\Non-School\Python\Handwritten Digits Recognition.py", line 38, in <module> X_train, y_train, X_test, y_test = load_dataset() TypeError: cannot unpack non-iterable NoneType object
I am new to machine learning. Did I just miss something simple? I am trying a Handwritten Digit Recognition project for my school Science Exhibition.
How to Fix “TypeError: Cannot Unpack Non-iterable NoneType Object” Error in Python. This error was raised because we tried to unpack a None object. The simplest way around this is to not assign names. sort() as the new value of your list.
The Python "TypeError: cannot unpack non-iterable int object" occurs when we try to unpack an integer value. To solve the error, track down where the variable got assigned an integer and correct the assignment to an iterable, e.g. a list or a tuple of integers.
The None keyword is used to define a null value, or no value at all. None is not the same as 0, False, or an empty string. None is a data type of its own (NoneType) and only None can be None.
If you are running your Python code and you see the error “TypeError: 'int' object is not iterable”, it means you are trying to loop through an integer or other data type that loops cannot work on.
You get this error when you perform a multiple assignment to None
(which is of NoneType
). For instance:
X_train, y_train, X_test, y_test = None
TypeError: cannot unpack non-iterable NoneType object
So if you get this, the error is most likely that the right-hand part of the assignment is not what you expected (it's nothing).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With