[Numpy-discussion] weird searchsorted behavior for unicode array

Thouis (Ray) Jones thouis at gmail.com
Wed Mar 28 10:55:47 EDT 2012


I am seeing some very strange behavior searching a unicode array.  The
attached code outputs the following:
UNICODE
Is sorted: True
Search sorted by iteration, left: [0, 1, 2, 4, 4, 6, 6, 8, 8, 10, 10,
12, 12, 13]
Search sorted by iteration, right: [0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10,
12, 12, 13]
Search sorted by indexing, left: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 13]
Search sorted by indexing, right: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 13]
Search sorted by indexing with copy, left: [1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 13]
Search sorted by indexing with copy, right: [1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12, 13, 13]

If I remove the first print, it produces:
Is sorted: True
Search sorted by iteration, left: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
Search sorted by iteration, right: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13]
Search sorted by indexing, left: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 13]
Search sorted by indexing, right: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 13]
Search sorted by indexing with copy, left: [0, 1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12, 13]
Search sorted by indexing with copy, right: [0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13]

Neither answer is correct, since left and right should be offset by 1
when searching for an element in the array, by my reading of the docs.

This is numpy 1.6.1 on OSX 10.6, python 2.7

Am I missing something?

Thanks,
Ray Jones
-------------- next part --------------
A non-text attachment was scrubbed...
Name: unicode_searchsorted.py
Type: application/octet-stream
Size: 2927 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20120328/59d65717/attachment.obj>


More information about the NumPy-Discussion mailing list