python如何保存.npy

2020/09/27 07:48

数据处理的时候主要通过两个函数:

(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学习网,免费的在线学习python平台,欢迎关注!

免费直播

    精选课程 更多

    注册电脑版

    版权所有 2003-2020 广州环球青藤科技发展有限公司