如何存储np.ndarray到文件?
How to store np.ndarray to file?
我有一个形状为 (15,11,5) 的 ndarray。如何将数组保存为11列15行的5个文件?
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')
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=',')
试试这个 ^
我有一个形状为 (15,11,5) 的 ndarray。如何将数组保存为11列15行的5个文件?
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')
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=',')
试试这个 ^