简体   繁体   English

在python3中加载.npy文件时返回的函数

[英]Function returned when loading .npy file in python3

I have stored a dict as diversity.npy. 我已经将字典存储为diversity.npy。 the dict structure: {key: array}. 字典结构:{key:array}。 when I use np.load to load diversity.npy: 当我使用np.load加载Diversity.npy时:

diver=np.load('diversity.npy').item()
print(diver)

if the environment is python27 ,it is correct to load the data. 如果环境是python27,则加载数据是正确的。 However function object is loaded in python34. 但是函数对象已加载到python34中。

<function diversity at 0x7fc0741977b8>

how to fix? 怎么修?

Here's a simple dictionary save in Py3.5 这是保存在Py3.5中的简单字典

In [157]: dd = {'x':np.array(10)}
In [158]: np.save('dd.npy', dd)
In [159]: data = np.load('dd.npy')
In [160]: data
Out[160]: array({'x': array(10)}, dtype=object)
In [161]: data.item()
Out[161]: {'x': array(10)}

It wrapped the dictionary in an object array, and saved that (using dictionary pickle). 它将字典包装在对象数组中,并将其保存(使用字典泡菜)。 item() takes the dictionary out of the array wrapper. item()将字典从数组包装器中取出。

pickle has problems crossing from py2 to py3 . pickle在从py2py3遇到问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM