[Numpy-discussion] String sort

Francesc Altet faltet@carabos....
Sat Feb 9 15:35:48 CST 2008


A Saturday 09 February 2008, Charles R Harris escrigué:
> On Feb 9, 2008 2:07 PM, Francesc Altet <faltet@carabos.com> wrote:
> > A Saturday 09 February 2008, Charles R Harris escrigué:
> > > > So, strncmp1 is not only faster than its C counterpart, but
> > > > also the one doing the correct job with NumPy (unicode)
> > > > strings.
> > >
> > > Ah, in that case the current indirect sort for NumPy strings,
> > > which uses strncmp, is incorrect and needs to be fixed. It seems
> > > that strings with zeros are not part of the current test series
> > > ;)
> >
> > Yeah, that's right.  And yes, it would be advisable to have at
> > least a couple of tests having zeros interspersed throughout the
> > string.
>
> Like this should do:
>
> In [5]: argsort(fromstring("\0\2\0\1", dtype="|S2"))
> Out[5]: array([0, 1])

Exactly, but I understand that the correct result should be:

array([1, 0])

;-)

Something a bit more complex, like:

In [5]: argsort(fromstring("a\0b\0\0\2a\0b\0\0\1", dtype="|S6"))
Out[5]: array([1, 0])

wouldn't hurt neither.

Cheers,

-- 
>0,0<   Francesc Altet     http://www.carabos.com/
V   V   Cárabos Coop. V.   Enjoy Data
 "-"


More information about the Numpy-discussion mailing list