recover dict from 0-d numpy array

前端 未结 2 1674
悲哀的现实
悲哀的现实 2020-12-12 22:00

What happened is that I (by mistake) saved a dictionary with the command numpy.save() (no error messages shown) and now I need to recover the data in the dictio

2条回答
  •  一个人的身影
    2020-12-12 22:26

    Use mydict.item() to obtain the array element as a Python scalar.

    >>> import numpy as np
    >>> np.save('/tmp/data.npy',{'a':'Hi Mom!'})
    >>> x=np.load('/tmp/data.npy')
    >>> x.item()
    {'a': 'Hi Mom!'}
    

提交回复
热议问题