数据处理的时候主要通过两个函数:
(1)np.save(“test.npy”,数据结构) ----存数据
(2)data =np.load('test.npy") ----取数据
给2个例子如下:
1、存列表
z = [[[1, 2, 3], ['w']], [[1, 2, 3], ['w']]] np.save('test.npy', z) x = np.load('test.npy') x: ->array([[list([1, 2, 3]), list(['w'])], [list([1, 2, 3]), list(['w'])]], dtype=object)
2、存字典
x -> {0: 'wpy', 1: 'scg'} np.save('test.npy',x) x = np.load('test.npy') x ->array({0: 'wpy', 1: 'scg'}, dtype=object)
3、在存为字典格式读取后,需要先调用如下语句
data.item()
将数据numpy.ndarray对象转换为dict。
python学习网,免费的在线学习,欢迎关注!
Copyright © 2019-2025 how234.cn 版权所有 赣ICP备2023008801号-2
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务