-
-
Notifications
You must be signed in to change notification settings - Fork 12.2k
Closed
Labels
Description
When using numpy.ma.dump to save a masked array in Python 3:
np.ma.dump(a, pathtofile)
I got the following error:
/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')
-> 7143 return pickle.dump(a, F)
7144
7145 def dumps(a):
TypeError: must be str, not bytes
This is with NumPy 1.9.1 and Python 3.3.2.
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 F = open(F, 'wb'). Indeed, if I were to change it to:
with open(pathtofile, 'wb') as f:
pickle.dump(a, f)
the error goes away.
Reactions are currently unavailable