Given two set of dict
saved using numpy savez
as below
import numpy as np
from numpy import load
names=['t1','t2','t3']
arr_name = np.array(names)
arr_val = np.array([1,2,3])
np.savez('data.npz', dict_one=dict(fone=arr_name,nval=arr_val),
dict_two=dict(fone=arr_name,nval=arr_val))
When reload the data as
dict_data = load('data.npz',allow_pickle=True)
ndata=dict_data['dict_one']
opt=ndata['fone']
The compiler return an error
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
May I know what is the issue here,and whether this is a good practice of saving multiple dict
with numpy arrays in it?
The output for print(ndata)
{'fone': array(['t1', 't2', 't3'], dtype='<U2'), 'nval': array([1, 2, 3])}
The output for print(dict_data )
<numpy.lib.npyio.NpzFile object at 0x7fe8887c6850>
Spec:
numpy 1.21.1 and Python 3.9.