Numpy error: oserror: failed to interpret file as a pickle

first understand the definition of pickle:

  • pickling: types and python data types used in python special conversion between
  • pickling provides four functions: dumps, dump, loads, the load
  • pickling can store all the python support of primitive types (Boolean, int, float, string, byte, none, etc.), made up of any native type lists and tuples, dictionaries, and collection, function, class, class instances.

so the error is essentially data file inconsistency, numpy difference between loadtxt() and load()

  • load() stands for saving data in Numpy’s proprietary binary format, which automatically processes information such as element types and shapes. Load usually reads.nPY or.npz files.
  • loadtxt() is mainly used to read TXT and other files

Following is the general use of loadtxt(), the most common is loadtxt(” filename. TXT “)

numpy.loadtxt(fname, dtype=, comments='#', delimiter=None, converters=None, skiprows=0, usecols=None, unpack=False, ndmin=0)

error is due to load() directly read the TXT file caused by unread. Use loadtxt() instead.

Read More: