我有几个numpy数组,只有一个包含整数。我想将它们组合成一个数组,并将其保存在一个.txt文件中。最后一行给我带来了麻烦,因为我试图将整数和字符串结合起来:
import numpy as np
specimen = np.array(['one1', 'two2', 'three3'])
outpath = '/some_folder/'
M1_x_list = np.array([1,2,3])
M1_y_list = np.array([2,3,4])
M1_z_list = np.array([4,5,6])
ALL_OUTPUT = np.asarray([specimen, M1_x_list, M1_y_list, M1_z_list]).T
print ALL_OUTPUT
np.savetxt(outpath+'test.txt', (ALL_OUTPUT), delimiter='\t', newline='\n', header='specimen \t x \t y \t z\t ', footer='')
我的预期产出是:
['one1' '1' '2' '4']
['two2' '2' '3' '5']
['three3' '3' '4' '6']
数组列表中缺少
dtype
。在行后添加dtype=int32
。你知道吗将int定义为字符串?你知道吗
int1=str( /*insert whatever your integer is here*/ )
然后将
int1
添加到数组中。你知道吗相关问题 更多 >
编程相关推荐