我有一个Python脚本,它创建了一个numpy数组。我应该如何将这个Numpy阵列保存到磁盘上,以便Comsol可以读取它?
这取决于软件所需的格式。如果你只想把它们放在一行中,用逗号连接,你可以这样做:
your_array = [1, 2, 3] # works the same for numpy array
your_seperator = "," # for new line use "n"
with open("path/to/your/file/your_array.txt", "w") as output_file:
output_file.write(your_seperator.join(your_array)
或者:
np.savetxt("your_array.csv", your_array, delimiter=",")