我有一個<class 'numpy.ndarray'>
對象,我希望將它保存在txt文件中。該物體具有尺寸(形狀)(130, 118, 118)
和尺寸1810120
。將numpy ndarray保存爲一個txt文件
當我嘗試使用np.savetxt(f, object, delimiter=' ', fmt='1.10f')
與f = open('test.txt', 'wb')
我收到錯誤
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\G****\Anaconda3\lib\site-packages\numpy\lib\npyio.py", line 1139, in savetxt
raise error
ValueError: fmt has wrong number of % formats: 1.10f
我試過1的F各種組合,但沒有工作過。建議任何人?
UPDATE: 以下從意見建議波紋管,並添加fmt='%1.10f'
後,我收到這樣的:
Traceback (most recent call last):
File "C:\Users\G****\Anaconda3\lib\site-packages\numpy\lib\npyio.py", line 1158, in savetxt
fh.write(asbytes(format % tuple(row) + newline))
TypeError: only length-1 arrays can be converted to Python scalars
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\G****\Anaconda3\lib\site-packages\numpy\lib\npyio.py", line 1162, in savetxt
% (str(X.dtype), format))
TypeError: Mismatch between array dtype ('int8') and format specifier ('%1.10f...... the '%1.10f goes on for quite a while)
嘗試:'fmt ='%1.10f'' –