numpy:savetxt数组dtype('int32')和格式说明符('%d')之间不匹配

时间:2016-04-22 13:01:23

标签: python numpy

我正在尝试使用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')

当我尝试输出扁平化数组并尝试将其输出到文件时,会出现类似的错误。

0 个答案:

没有答案