【numpy学习笔记】数组的存储和下载

1. Saving array in binary format (.npy)

>>>a = np.array([1,2,3,4,5])
>>>np.save('array_a',a)
>>>np.load('array_a.npy')
array([1, 2, 3, 4, 5])

2. Saving multiple arrays into a zip file

>>>b = np.array([[1,2,3],[4,5,6]])
>>>np.savez('two_arrays.npz',x=b,y=b.T)
>>>np.load('two_arrays.npz')['x']
array([[1, 2, 3],
       [4, 5, 6]])
>>>np.load('two_arrays.npz')['y']
array([[1, 4],
       [2, 5],
       [3, 6]])

3. Saving and loading into text files

>>>b = np.array([[1,2,3],[4,5,6]])
>>>np.savetxt('array_text.txt',b,delimiter=',')
>>>np.loadtxt('array_text.txt',delimiter=',')
array([[ 1.,  2.,  3.],
       [ 4.,  5.,  6.]])

你可能感兴趣的:(python)