shaoheshaohe 发表于 2020-5-25 17:04:48

python 存取字典dict via numpy

数据处理的时候主要通过两个函数
(1):np.save(“test.npy”,数据结构) ----存数据
(2):data =np.load('test.npy") ----取数据1、存列表https://common.cnblogs.com/images/copycode.gif
1 z = [[, ['w']], [, ['w']]]2 np.save('test.npy', z)3 x = np.load('test.npy')4 5 x:6 ->array([), list(['w'])],7      ), list(['w'])]], dtype=object)https://common.cnblogs.com/images/copycode.gif


2、存字典https://common.cnblogs.com/images/copycode.gif
1 x2 -> {0: 'wpy', 1: 'scg'}3 np.save('test.npy',x)4 x = np.load('test.npy')5 x6 ->array({0: 'wpy', 1: 'scg'}, dtype=object)https://common.cnblogs.com/images/copycode.gif

3、在存为字典格式读取后,需要先调用如下语句(重点!!!)1 data.item()
将数据numpy.ndarray对象转换为dict

shaoheshaohe 发表于 2020-5-25 17:04:58

https://www.cnblogs.com/shanyr/p/11243889.html
页: [1]
查看完整版本: python 存取字典dict via numpy