我正在尝试使用savetxt
保存数组。这是我的工作:
import numpy
import sys
a = numpy.asarray(((1,2,3),(4,5,6)))
numpy.savetxt(sys.stdout, a, fmt='%d')
我得到了什么:
Traceback (most recent call last):
File "C:\Users\George\Documents\My\contests-penza-su-2016\env\lib\site-packages\numpy\lib\npyio.py", line 1158, in savetxt
fh.write(asbytes(format % tuple(row) + newline))
TypeError: write() argument must be str, not bytes
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Users\George\Documents\My\contests-penza-su-2016\env\lib\site-packages\numpy\lib\npyio.py", line 1162, in savetxt
% (str(X.dtype), format))
TypeError: Mismatch between array dtype ('int32') and format specifier ('%d %d %d')
当我尝试输出扁平化数组并尝试将其输出到文件时,会出现类似的错误。