<p dir="auto">I apologise if I'm using this incorrectly, but I could not find anything relevant in the issue list, and as far as I can work out, this really should work.</p>
<p dir="auto">If I pass an array with unicode objects (instead of 'string' objects) into savetxt, it bombs out, trying to run the unicode object through the 'asbytes' function.</p>
<p dir="auto">It does not change things if the dtype of the array is 'U' instead of 'S'.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; import numpy as np; np.savetxt('test.csv', np.array(['this wörks', u'this dös not']), fmt=['%s'])
---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
&lt;ipython-input-5-6a3125624190&gt; in &lt;module&gt;()
----&gt; 1 import numpy as np; np.savetxt('test.csv', np.array(['this wörks', u'this dös not']), fmt=['%s'])
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 6: ordinal not in range(128)'"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; import numpy as np; np.savetxt('test.csv', np.array(['this wörks', u'this dös not']), fmt=['%s'])
---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
&lt;ipython-input-5-6a3125624190&gt; in &lt;module&gt;()
----&gt; 1 import numpy as np; np.savetxt('test.csv', np.array(['this wörks', u'this dös not']), fmt=['%s'])
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 6: ordinal not in range(128)'
</code></pre></div>
<p dir="auto"><strong>numpy.savetxt</strong> uses under the hood <em>the numpy.compat.py3k.asbytes</em> utility function. In python 3 and above the function forces decoding of the data into 'latin1'.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="  File &quot;C:\Python33\lib\site-packages\numpy\lib\npyio.py&quot;, line 1073, in savetxt
    fh.write(asbytes(format % tuple(row) + newline))
  File &quot;C:\Python33\lib\site-packages\numpy\compat\py3k.py&quot;, line 31, in asbytes
    return str(s).encode('latin1')
UnicodeEncodeError: 'latin-1' codec can't encode character '\u2009' in position 12: ordinal not in range(256)"><pre class="notranslate"><code class="notranslate">  File "C:\Python33\lib\site-packages\numpy\lib\npyio.py", line 1073, in savetxt
    fh.write(asbytes(format % tuple(row) + newline))
  File "C:\Python33\lib\site-packages\numpy\compat\py3k.py", line 31, in asbytes
    return str(s).encode('latin1')
UnicodeEncodeError: 'latin-1' codec can't encode character '\u2009' in position 12: ordinal not in range(256)
</code></pre></div>
<p dir="auto">It would be better to allow overriding the default encoding for the function (or even default it to 'utf-8').</p>