我有一个<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'' –