我有一個形狀為 (15,11,5) 的 ndarray。如何將陣列保存為 5 個包含 11 列和 15 行的檔案?
import numpy as np
a = np.ndarray(shape=(15,11,5), dtype=float, order='F')
for i in range(5):
with open('file{i}.txt', 'wb') as f:
np.savetxt(f, np.column_stack(a[:,:,i]), fmt='%1.10f')
uj5u.com熱心網友回復:
import numpy as np
a = np.ndarray(shape=(11,15,11), dtype=float, order='F')
k = 0
for j in a:
k =1
with open(f'file{k}.txt', 'wb') as f:
np.savetxt(f, j, fmt='%1.10f', delimiter=',')
試試這個^
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/433105.html
標籤:python-3.x 文件 numpy-ndarray
上一篇:在r中移動檔案時出現錯誤
