[Numpy-tickets] [NumPy] #341: Inconsistent behavior of comparison operators on character arrays, created with 'c' typecode
NumPy
numpy-tickets at scipy.net
Fri Oct 13 00:41:05 CDT 2006
#341: Inconsistent behavior of comparison operators on character arrays, created
with 'c' typecode
---------------------+------------------------------------------------------
Reporter: gkoczyk | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone:
Component: Other | Version: devel
Severity: normal | Keywords:
---------------------+------------------------------------------------------
Arrays created using old Numeric 'c' typecode, seem to have '|S1'
datatype, but raise errors on comparison with Python strings or sequences.
{{{
>>> numpy.array([ 'X' ], 'c')
array(['X'],
dtype='|S1')
>>> numpy.array([ 'X' ], 'c') == 'X'
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: invalid string data-types in comparison
>>> numpy.array([ 'X', 'X' ], 'c') < ['X']
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: invalid string data-types in comparison
}}}
On a sidenote, functor objects implementing comparisons on '|S1' arrays
raise NotImplemented :
:
{{{
>>> numpy.equal( numpy.array([ 'X', 'X' ], 'c') , numpy.array( ['X', 'X'],
'c' ) )
NotImplemented
>>> numpy.equal( numpy.array([ 'X', 'X' ], 'c') , numpy.array( ['X', 'X'],
'|S1' ) )
NotImplemented
>>> numpy.equal( numpy.array([ 'X', 'X' ], '|S1') , numpy.array( ['X',
'X'], '|S1' ) )
NotImplemented
}}}
--
Ticket URL: <http://projects.scipy.org/scipy/numpy/ticket/341>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.
More information about the Numpy-tickets
mailing list