I was trying to make another point and accidentally saved a dict
using numpy np.save()
. To my surprise there seem to be no problem at all with that approach. I tried the above with another object that it's not np.array
like a list
and it seem to work fine.
For example the following code, saves and loads an object using np.save()
and np.load()
:
list_file = 'random_list.npy'
random_list = [x*2 for x in range(20)]
np.save(list_file, random_list)
# load numpy array
random_list2 = np.load(list_file)
set(random_list) == set(random_list2)
True
So, my question is:
- Why is this succeeding anyway since in the documentation only arrays are mentioned?
- And similarly if it was meant to deal with other objects, which objects can be handled?
I know there are some limitation regarding pickle which could affect the nature of object that could be handled but a lot of unclear points still exist.
Edit:
I thought that np.save()
was just trying to convert the object passed as parameter to numpy array but that does not make any sense in some cases like dict
.
For example a dict
passed to a np.array does not seem to be functional at all:
a = {1: 0, 2: 1, 3: 2}
b = np.array(a)
type(b)
numpy.ndarray
b.shape
()