import numpy as np

dict = {'a' : {1,2,3}, 'b': {4,5,6}}

np.save('dict.npy', dict)
    
dict_load=np.load('dict.npy', allow_pickle=True)
    
print("dict =", dict_load.item())
print("dict['a'] =", dict_load.item()['a'])

读取的时候如果不用dict_load.item()['a'],而是直接用dict_load['a'],会报如下错误:

IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices

相关文章:

  • 2021-10-10
  • 2022-12-23
  • 2021-08-17
  • 2021-12-17
  • 2021-09-02
  • 2021-12-22
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案