Python 在数组中组合整数和字符串并保存到文本文件

Python 在数组中组合整数和字符串并保存到文本文件,python,arrays,string,numpy,Python,Arrays,String,Numpy,我有几个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

我有几个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']
将int定义为字符串

int1=str(/*插入此处的整数*/)


然后将
int1
添加到数组中。

您的数组列表中缺少
dtype
。在行后添加
dtype=int32

在使用
ALL\u OUTPUT=np.asarray([sample,M1\u x\u list,M1\u y\u list,M1\u z\u list])行后。T
将数组转换为
str
。您可以查看
dtype
谢谢。我以前偶然发现了dtype,但我不知道如何在我的案例中实现它。您能附上您的预期输出吗?第一行:one1 2 4,第二行:two2 2 3 5,第三行:three3 4 5 6(对不起,我不知道如何在注释中打断行。最好用您的预期输出更新您的问题。