[SciPy-user] Print unicode objects in object arrays

mmanns@gm... mmanns@gm...
Tue May 26 17:33:41 CDT 2009


Hi

Is there a way of printing unicode objects that are inside an object
array?

$ python
Python 2.5.4 (r254:67916, Feb 17 2009, 20:16:45) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> u = [u'\u201e']
>>> u
[u'\u201e']
>>> import numpy
>>> a = numpy.array(u, dtype="O")
>>> a
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.5/site-packages/numpy/core/numeric.py", line
1088, in array_repr ', ', "array(")
  File "/usr/lib/python2.5/site-packages/numpy/core/arrayprint.py",
line 287, in array2string separator, prefix)
  File "/usr/lib/python2.5/site-packages/numpy/core/arrayprint.py",
line 216, in _array2string _summaryEdgeItems, summary_insert)[:-1]
  File "/usr/lib/python2.5/site-packages/numpy/core/arrayprint.py",
line 333, in _formatArray word = format_function(a[-1])
UnicodeEncodeError: 'ascii' codec can't encode character u'\u201e' in
position 0: ordinal not in range(128)
>>> numpy.__version__
'1.2.1'

Thanks in advance

Martin



More information about the SciPy-user mailing list