我试图将一个numpy的维数组(22227,2)转换成一个2列22227行的csv文件,但是,每当我尝试用下面的代码做这个时,我得到的是一行的列数是原来的两倍。
# using open function
sample_data = np.genfromtxt("wg1_regular_baseline_trial6.csv",delimiter=",", dtype=float)
sample_data = np.array(sample_data)
s_data=sample_data[1000:-4000]
#find mean of original data
adjusted_value=[]
mean_wave=sample_data[:,1].mean()
#adjust data for mean value
for i in range(len(sample_data)):
value=sample_data[i]
adjusted_value+=[[value[0],value[1]-mean_wave]]
#create array
adjusted_data = np.array(adjusted_value)
a_data=adjusted_data[1000:-4000]
print(np.shape(adjusted_data))
#create csv file
adjusted_data.tofile('BL_Trial6.csv', sep = ',')
打印调整后数据的数组时输出的代码为
[[0.00000000e+00 2.63267449e-02]
[1.00000000e-02 2.64037449e-02]
[2.00000000e-02 2.62877449e-02]
...
[2.22240000e+02 9.33474486e-03]
[2.22250000e+02 1.04347449e-02]
[2.22260000e+02 1.15347449e-02]]
我试图使用numpy整形工具,但没有成功,因为它仍然打印一行与许多许多列。
1条答案
按热度按时间50few1ms1#
对于简单的(2,2)数组:
比较
tofile
:使用
savetxt
: