I have .npy files that were created using Python 2.7.9 and Numpy Version 1.11.3 with the command np.save('filename'). The files were produced on an external machine that is part of the linux-cluster of our institute. I copied the files to my local machine in order to import them via np.load('filename.npy'). On my local machine I am running Python 3.5.2 and Numpy Version 1.13.0 with Jupyter-Notebook. The local OS is Ubuntu 16.04.2.
When I try to load the files locally I get the error:
ValueError: invalid literal for int() with base 16
After browsing through some Stackoverflow questions I tried to specify the encoding with:
np.load('filename.npy',encoding='latin1')
This gives the same error. encoding='bytes' yields:
TypeError: can't multiply sequence by non-int of type 'float'
Here is a larger snippet of the Traceback:
/usr/local/lib/python3.5/dist-packages/numpy/lib/npyio.py in load(file, mmap_mode, allow_pickle, fix_imports, encoding)
417 else:
418 return format.read_array(fid, allow_pickle=allow_pickle,
--> 419 pickle_kwargs=pickle_kwargs)
420 else:
421 # Try a pickle
/usr/local/lib/python3.5/dist-packages/numpy/lib/format.py in read_array(fp, allow_pickle, pickle_kwargs)
638 pickle_kwargs = {}
639 try:
--> 640 array = pickle.load(fp, **pickle_kwargs)
641 except UnicodeError as err:
642 if sys.version_info[0] >= 3:
/usr/local/lib/python3.5/dist-packages/sympy/core/numbers.py in __new__(cls, num, prec)
823 else:
824 _mpf_ = mpmath.mpf(
--> 825 S.NegativeOne**num[0]*num[1]*2**num[2])._mpf_
826 elif isinstance(num, Float):
827 _mpf_ = num._mpf_
TypeError: can't multiply sequence by non-int of type 'float'
I guess that something with the encoding went wrong on the transition between the Python and Numpy versions. Any ideas on how I can import the files?
%%python2at the beginning of the notebook cell to do so). But using Python 2 leads to further errors such that I was looking for a solution to stick with Python 3 for the usage of these files.object. The error is inpickle_load, suggesting the later.np.savedocs has some cautions regarding PY2/3 compatibility when pickling objects.sympy.core.numbers.Float. Saving and loading with NumPy leads to an array withdtype=object. I guess a proper workaround for my problem is to convert the SymPy-Number to a Python-Float before writing it into the list. @cat thank you for your explinations as well!