Pickle incompatibility of numpy arrays between Python 2 and 3

前端 未结 7 1573
遥遥无期
遥遥无期 2020-11-28 01:12

I am trying to load the MNIST dataset linked here in Python 3.2 using this program:

import pickle
import gzip
import numpy


with gzip.open(\'mnist.pkl.gz\',         


        
相关标签:
7条回答
  • 2020-11-28 02:11

    Try:

    l = list(pickle.load(f, encoding='bytes')) #if you are loading image data or 
    l = list(pickle.load(f, encoding='latin1')) #if you are loading text data
    

    From the documentation of pickle.load method:

    Optional keyword arguments are fix_imports, encoding and errors, which are used to control compatibility support for pickle stream generated by Python 2.

    If fix_imports is True, pickle will try to map the old Python 2 names to the new names used in Python 3.

    The encoding and errors tell pickle how to decode 8-bit string instances pickled by Python 2; these default to 'ASCII' and 'strict', respectively. The encoding can be 'bytes' to read these 8-bit string instances as bytes objects.

    0 讨论(0)
提交回复
热议问题