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

猜你喜欢

转载自www.cnblogs.com/shanyr/p/11243889.html