我有一个 python 列表
temp = [['abc.jpg', 1, 2, 3, 'xyz'], ['def.jpg', 4,5,6, 'xyz']]
要将其保存为数组,所以我这样做:
temp = np.vstack(temp)
结果:
print(temp)
temp = [['abc.jpg', '1', '2', '3', 'xyz'], ['def.jpg', '4','5','6', 'xyz']]
它正在将整数转换为字符串。我不希望这种事发生。
我想将结果保存在文本文件中。
我尝试了以下方法:
np.savetxt("data.txt", temp)
但我收到以下错误:
TypeError: Mismatch between array dtype ('<U8') and format specifier ('%.18e %.18e %.18e %.18e %.18e %.18e')
最佳答案
试试这个(它保存用“;”分隔的每一行):
np.savetxt("data.txt", temp, delimiter=" ", newline = "\n", fmt="%s")
关于python - 将字符串和整数数组保存到python中的文本文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47033153/