<p dir="auto">numpy.ma.load() fails on files generated bu numpy.ma.dump() in python3. See the following code:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from __future__ import print_function
import sys
import numpy as np

print(&quot;Python version:&quot;, sys.version)
print(&quot;Numpy version:&quot;, np.version.full_version)

mma = np.ma.ones((4,4))
mma.dump(&quot;mma.dat&quot;)

mmb = np.ma.load(&quot;mma.dat&quot;)"><pre class="notranslate"><span class="pl-k">from</span> __future__ <span class="pl-k">import</span> <span class="pl-s1">print_function</span>
<span class="pl-k">import</span> <span class="pl-s1">sys</span>
<span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>

<span class="pl-en">print</span>(<span class="pl-s">"Python version:"</span>, <span class="pl-s1">sys</span>.<span class="pl-s1">version</span>)
<span class="pl-en">print</span>(<span class="pl-s">"Numpy version:"</span>, <span class="pl-s1">np</span>.<span class="pl-s1">version</span>.<span class="pl-s1">full_version</span>)

<span class="pl-s1">mma</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-s1">ma</span>.<span class="pl-en">ones</span>((<span class="pl-c1">4</span>,<span class="pl-c1">4</span>))
<span class="pl-s1">mma</span>.<span class="pl-en">dump</span>(<span class="pl-s">"mma.dat"</span>)

<span class="pl-s1">mmb</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-s1">ma</span>.<span class="pl-en">load</span>(<span class="pl-s">"mma.dat"</span>)</pre></div>
<p dir="auto">And now let's run it:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="laptop:~/py/Varie/testNPdump$ python testMAdump.py 
Python version: 2.7.12 (default, Nov 20 2017, 18:23:56) 
[GCC 5.4.0 20160609]
Numpy version: 1.13.3"><pre class="notranslate"><code class="notranslate">laptop:~/py/Varie/testNPdump$ python testMAdump.py 
Python version: 2.7.12 (default, Nov 20 2017, 18:23:56) 
[GCC 5.4.0 20160609]
Numpy version: 1.13.3
</code></pre></div>
<p dir="auto">Now with python3:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="lfini@lfini-laptop:~/py/Varie/testNPdump$ python3 testMAdump.py 
Python version: 3.5.2 (default, Nov 23 2017, 16:37:01) 
[GCC 5.4.0 20160609]
Numpy version: 1.13.3
Traceback (most recent call last):
  File &quot;testMAdump.py&quot;, line 11, in &lt;module&gt;
    mmb = np.ma.load(&quot;mma.dat&quot;)
  File &quot;/usr/local/lib/python3.5/dist-packages/numpy/ma/core.py&quot;, line 7868, in load
    return pickle.load(F)
  File &quot;/usr/lib/python3.5/codecs.py&quot;, line 321, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte"><pre class="notranslate"><code class="notranslate">lfini@lfini-laptop:~/py/Varie/testNPdump$ python3 testMAdump.py 
Python version: 3.5.2 (default, Nov 23 2017, 16:37:01) 
[GCC 5.4.0 20160609]
Numpy version: 1.13.3
Traceback (most recent call last):
  File "testMAdump.py", line 11, in &lt;module&gt;
    mmb = np.ma.load("mma.dat")
  File "/usr/local/lib/python3.5/dist-packages/numpy/ma/core.py", line 7868, in load
    return pickle.load(F)
  File "/usr/lib/python3.5/codecs.py", line 321, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte
</code></pre></div>
<p dir="auto">When using numpy.ma.dump to save a masked array in Python 3:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="np.ma.dump(a, pathtofile)"><pre class="notranslate"><code class="notranslate">np.ma.dump(a, pathtofile)
</code></pre></div>
<p dir="auto">I got the following error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="/home/btan1/.virtualenvs/python3.3/lib/python3.3/site-packages/numpy/ma/core.py in dump(a, F)
   7141     if not hasattr(F, 'readline'):
   7142         F = open(F, 'w')
-&gt; 7143     return pickle.dump(a, F)
   7144 
   7145 def dumps(a):

TypeError: must be str, not bytes"><pre class="notranslate"><code class="notranslate">/home/btan1/.virtualenvs/python3.3/lib/python3.3/site-packages/numpy/ma/core.py in dump(a, F)
   7141     if not hasattr(F, 'readline'):
   7142         F = open(F, 'w')
-&gt; 7143     return pickle.dump(a, F)
   7144 
   7145 def dumps(a):

TypeError: must be str, not bytes
</code></pre></div>
<p dir="auto">This is with NumPy 1.9.1 and Python 3.3.2.</p>
<p dir="auto">From what I found out, it is because in Python 3 pickle files has to be opened in binary mode, i.e. L7142 should be <code class="notranslate">F = open(F, 'wb')</code>. Indeed, if I were to change it to:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="with open(pathtofile, 'wb') as f:
    pickle.dump(a, f)"><pre class="notranslate"><code class="notranslate">with open(pathtofile, 'wb') as f:
    pickle.dump(a, f)
</code></pre></div>
<p dir="auto">the error goes away.</p>