array([[list([1, 2, 3]), list([w])],       [list([1" />
首页 > 文章列表 > python如何保存.npy

python如何保存.npy

Python 保存 .npy
217 2022-08-07

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

(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。