简体   繁体   中英

Read npy data file in Python and export as text file

I have an array saved in a npy file and want to export it into readable text columns.

The array is here: https://drive.google.com/open?id=1DErx4e0NBJJNxixMSuGQaahdAcGX7jkI

I did the following:

import numpy as np
data = np.load('D:/20190805_01_data.npy')

type(data ) gives numpy.ndarray

len(data) gives 1363

data.ndim gives 3

To export data I tried:

np.savetxt('D:/data.txt',data, delimiter=' ')

which does not work.

What is the correct solution?

it seems that your data have one extra dimension

data.shape
Out[4]: (1363, 1, 2)

You can do the following to remove this dimension :

data = np.squeeze(data)

and then save data to a .txt file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM