[Numpy-discussion] stringscalar comparisons with a chararray

Michael Sorich michael.sorich at gmail.com
Tue Mar 28 22:47:04 EST 2006


As shown in the example below, chararray comparisons do not seem to work
well when stringscalars are used. In the example below I am also curious as
to whether the the length of  c[0] should be 2 instead of 5.

 numpy.__version__ 0.9.6
>>> from numpy import *
>>> c =char.array(['on','two','three'])
>>> c
chararray([on, two, three],
      dtype='|S5')
>>> c=='on'
array([True, False, False], dtype=bool)
>>> c==c[0]
array([False, False, False], dtype=bool)
>>> c==str(c[0])
array([True, False, False], dtype=bool)
>>> c[0]
'on'
>>> len(c[0])
5
>>> c.dtype
dtype('|S5')
>>> c==c[2]
array([False, False, True], dtype=bool)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20060328/40d678ea/attachment.html>


More information about the NumPy-Discussion mailing list