我正在尝试保存一个像这样的三列矩阵
[ ['1/0' '-2.0' '2.3058220360827992e-11'],
['1.0/0.02857142857142857' '-2.0' '2.010818928071975e-12'],
['1.0/0.05714285714285714' '-2.0' '5.8909978692050895e-12']]
使用np.savetxt
我尝试用
定义列np.savetxt('FFT', RESULT, fmt=' '.join(['%s'] + ['%f']*2))
和
np.savetxt('FFT', RESULT,fmt='%s %1.4f %1.4f')
但是它总是给我同样的错误
Traceback (most recent call last)
~/anaconda3/lib/python3.7/site-packages/numpy/lib/npyio.py in savetxt(fname, X, fmt, delimiter, newline, header, footer, comments, encoding)
1386 try:
-> 1387 v = format % tuple(row) + newline
1388 except TypeError:
TypeError: must be real number, not numpy.str_
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
<ipython-input-17-eecf9f5ea0b0> in <module>
58 RESULT = np.delete(RESULT, (0), axis=0)
59 print (RESULT)
---> 60 np.savetxt('FFT', RESULT, fmt=' '.join(['%s'] + ['%f']*2))
61
62
~/anaconda3/lib/python3.7/site-packages/numpy/lib/npyio.py in savetxt(fname, X, fmt, delimiter, newline, header, footer, comments, encoding)
1389 raise TypeError("Mismatch between array dtype ('%s') and "
1390 "format specifier ('%s')"
-> 1391 % (str(X.dtype), format))
1392 fh.write(v)
1393
TypeError: Mismatch between array dtype ('<U23') and format specifier ('%s %f %f')
我想将其保存为三行,以便具有等距x轴的3d图,x轴以“ 1 / something”作为标签,y轴由第二行的勇气和第三列的勇气决定。 matplotlib,热图上的颜色。无论如何,这对于这个问题并不重要。 对不起,英语不好,谢谢您的帮助!