【发布时间】:2015-07-07 18:31:10
【问题描述】:
如何恢复被转换为numpy ndarray 的dict?
即对于以下示例,我想从test_array 恢复test_dict:
>>> test_dict = { 'one' : 1 }
>>> test_array = np.asarray(test_dict)
>>> print repr(test_array)
array({'one': 1}, dtype=object)
这些不起作用:
>>> test[0]
IndexError: 0-d arrays can't be indexed
>>> dict(test)
TypeError: iteration over a 0-d array
>>> test.astype(dict)
array({'one': 1}, dtype=object) # still in array
【问题讨论】:
标签: python arrays numpy dictionary