Problem using numpy.load

I have the following data written in python 2 that I would like to load into a python 3 file.

import numpy as np
x = np.array([{'a': np.array([1., 2., 3])}])
np.save('data.npy', x)

My first attempt:

import numpy as np
x = np.load('data.npy')

UnicodeError: Unpickling a python object failed

After playing back the source data I'm trying to load, it seems that whenever I have numpy-float inside the numpy array inside the python dictionary, I get an error. I can load a dictionary, I can load a numpy array, I can even load a numpy array inside a python dictionary, but as soon as I have numpy floats inside a numpy array inside a python dictionary, I get an error. My second attempt:

import numpy as np
x = np.load('data.npy', encoding = 'bytes')
x

array([{b'a': array([ 1.,  2.,  3.])}], dtype=object)

This worked so that I could load the data, but he added a "b" before each key in the dictionary. I was wondering if anyone has an idea of ​​why this problem occurs and how to fix it.

Thank!

edit:

, :

import numpy as np
x = np.load('data.npy', encoding = 'latin1')
+4
1

Python 2 - ascii; Python 3 utf-8. latin1 (a.k.a., ISO-8859-1) ascii. ascii - latin1 , ascii.

+6

All Articles