我在将以下数组写入 .txt 文件时遇到问题。
这是我的代码:
for i in range(len(my_particles)):
list = []
list.append(my_particles[i].n)
for z in range(len(my_particles[i].neighbours)):
list.append(my_particles[i].neighbours[z])
#for i in range(len(list)):
print >>f, list
f.close()
这是输出:
[0, 2, 20, 91, 114, 127]
[1, 6, 24, 114]
[2, 0, 65, 73, 91, 114]
[3, 71, 91, 120]
[4, 16, 69, 104]
[6, 1, 25, 87, 100, 114]
[7, 19, 83, 111]
[9, 38, 59, 72, 76]
[11, 56, 101, 108]
[12, 86, 92, 126]
[13, 30, 79, 82, 101, 104]
[14, 78, 103, 124]
[15, 23, 44, 90, 116]
[16, 4, 97, 106, 108]
[17, 19, 85, 111]
[18, 47, 60, 68, 74]
有没有办法以这种格式打印它?
0, 2, 20, 91, 114, 127
1, 6, 24, 114
我努力了
print>>f, "".join(list)
但它不起作用,因为它是一个 numpy64 浮点数列表。