我想將兩個一維陣列保存為文本檔案中的兩列,以便以后能夠打開此檔案并繪制其中一列我使用了以下內容:
file = open("myfile.txt", "w")
print(s, beta,, file=file)
file.close()
現在,當查看輸出檔案時,我看到陣列存盤為
[ 1.4 4.31 7.21 10.12 13.02 15.93 18.83 21.74 24.64 27.55
30.45 33.36 36.26 39.17 42.07 44.98 47.88 50.79 53.69 56.6
59.5 62.41 65.31 68.22 71.12 74.03 76.93 79.84 82.74 85.65
88.55 91.46 94.36 97.27 100.17 103.08 105.98 108.89 111.79 114.7 ] [5.7882581 3.09619004 5.7882581 3.09619004 5.7882581 3.09619004
5.7882581 3.09619004 5.7882581 3.09619004 5.7882581 3.09619004
5.7882581 3.09619004 5.7882581 3.09619004 5.7882581 3.09619004
5.7882581 3.09619004 5.7882581 3.09619004 5.7882581 3.09619004
5.7882581 3.09619004 5.7882581 3.09619004 5.7882581 3.09619004
5.7882581 3.09619004 5.7882581 3.09619004 5.7882581 3.09619004
5.7882581 3.09619004 5.7882581 3.09619004]
所以我試圖將陣列行轉換為列:
file = open("myfile.txt", "w")
print(s.T, beta.T,, file=file)
file.close()
我仍然看不到變化,
我的問題是如何將陣列元素保存為 txt 檔案中的列?
uj5u.com熱心網友回復:
如果只是為另一次運行保存資料,您可以使用pickle:
import pickle
with open("data.pickle", "wb") as file:
pickle.dump(YOUR_LIST, file)
您可以像這樣保存在txt檔案中:
with open("myfile.txt", "w") as file:
for line in YOUR_LIST:
file.write(" ".join(line))
uj5u.com熱心網友回復:
我使用 Pandas 將資料作為 DataFrame 保存在 csv 檔案中,.
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/436829.html
上一篇:如何訪問陣列陣列中的變數?
