title: Pickle incompatibility of numpy arrays between Python 2 and 3
body: <p>I am trying to load the MNIST dataset linked <a href="http://deeplearning.net/tutorial/gettingstarted.html" rel="noreferrer">here</a> in Python 3.2 using this program:</p>
  
  <pre><code>import pickle
  import gzip
  import numpy
  
  
  with gzip.open('mnist.pkl.gz', 'rb') as f:
      l = list(pickle.load(f))
      print(l)
  </code></pre>
  
  <p>Unfortunately, it gives me the error:</p>
  
  <pre><code>Traceback (most recent call last):
     File "mnist.py", line 7, in &lt;module&gt;
       train_set, valid_set, test_set = pickle.load(f)
  UnicodeDecodeError: 'ascii' codec can't decode byte 0x90 in position 614: ordinal not in range(128)
  </code></pre>
  
  <p>I then tried to decode the pickled file in Python 2.7, and re-encode it.  So, I ran this program in Python 2.7:</p>
  
  <pre><code>import pickle
  import gzip
  import numpy
  
  
  with gzip.open('mnist.pkl.gz', 'rb') as f:
      train_set, valid_set, test_set = pickle.load(f)
  
      # Printing out the three objects reveals that they are
      # all pairs containing numpy arrays.
  
      with gzip.open('mnistx.pkl.gz', 'wb') as g:
          pickle.dump(
              (train_set, valid_set, test_set),
              g,
              protocol=2)  # I also tried protocol 0.
  </code></pre>
  
  <p>It ran without error, so I reran this program in Python 3.2:</p>
  
  <pre><code>import pickle
  import gzip
  import numpy
  
  # note the filename change
  with gzip.open('mnistx.pkl.gz', 'rb') as f:
      l = list(pickle.load(f))
      print(l)
  </code></pre>
  
  <p>However, it gave me the same error as before.  How do I get this to work?</p>
  
  <hr>
  
  <p><a href="http://scikit-learn.org/stable/modules/generated/sklearn.datasets.fetch_mldata.html" rel="noreferrer">This is a better approach for loading the MNIST dataset.</a></p>