[英]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.我有一个保存在 npy 文件中的数组,并希望将其导出到可读的文本列中。
The array is here: https://drive.google.com/open?id=1DErx4e0NBJJNxixMSuGQaahdAcGX7jkI阵列在这里: 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
type(data
) 给出numpy.ndarray
len(data)
gives 1363
len(data)
给出1363
data.ndim
gives 3
data.ndim
给出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.然后将
data
保存到 .txt 文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.