python 存取字典dict

数据处理的时候主要通过两个函数
(1):np.save(“test.npy”,数据结构) ----存数据
(2):data =np.load('test.npy") ----取数据

1、存列表

1 z = [[[1, 2, 3], ['w']], [[1, 2, 3], ['w']]]
2 np.save('test.npy', z)
3 x = np.load('test.npy')
4 
5 x:
6 ->array([[list([1, 2, 3]), list(['w'])],
7        [list([1, 2, 3]), list(['w'])]], dtype=object)

 

2、存字典

1 x
2 -> {0: 'wpy', 1: 'scg'}
3 np.save('test.npy',x)
4 x = np.load('test.npy')
5 x
6 ->array({0: 'wpy', 1: 'scg'}, dtype=object)

3、在存为字典格式读取后,需要先调用如下语句(重点!!!)

1 data.item()

将数据numpy.ndarray对象转换为dict

posted on   若流芳千古  阅读(16276)  评论(0编辑  收藏  举报

努力加载评论中...

导航

< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8
点击右上角即可分享
微信分享提示