[SciPy-dev] Example of power of new data-type descriptors.
Travis Oliphant
oliphant.travis at ieee.org
Sat Jan 7 22:36:04 EST 2006
Hugo Gamboa wrote:
>I was looking at these new datatype mechanisms, and was unable to make
>an array string compare.
>
>example: (using Travis code)
>
>a['name']
>Out[49]: array([Bill, Fred], dtype=(string,30))
>
>In [50]: a['name']=='Bill'
>Out[50]: False
>
>In [51]: a['name'].__eq__('Bill')
>Out[51]: NotImplemented
>
>
>I expected that a['name']=='Bill' would return [True, False]
>
>
Problem is nobody has implemented that yet for strings. Comparisons go
through universal functions. And there is no support for
flexible-length arrays in the universal functions (ufuncs) right now.
We could special-case the (rich) comparisons for strings and unicodes
rather easily (and I think we should), but that hasn't been done yet.
Right now, the chararray does implement equality testing (in Python so
more slowly).
Use a.view(numpy.chararray) to get a chararray. But, note the
chararray has not been well-tested, yet.
-Travis
More information about the SciPy-Dev
mailing list