[Numpy-discussion] searchsorted descending arrays

Bago mrbago at gmail.com
Mon May 6 18:54:33 EDT 2013


I submitted a patch a little while ago,
https://github.com/numpy/numpy/pull/3107, which gave the searchsorted
function the ability to search arrays sorted in descending order. At the
time my  approach was to detect the sortorder of the array by comparing the
first and last elements. This works pretty well in most cases, but fails in
one notable case. After giving it some thought, I think the best way to add
searching of descending arrays to numpy would be by adding a keyword to the
searchsorted function. I wanted to know what you guys thought of this
before updating the pr.

I would like to add something like the following to numpy:

A = [10, 9, 2, 1]
np.searchsorted(A, 5, sortorder='descending')

the other option would be to auto-detect the order, but then this case
might surprise some users:

A = [0, 0, 0]
A = np.sort(A)[::-1]
print np.searchsorted(A, [1, -1])
# [3, 0]

This might surprise a user who expects to be searching a descending array


Bago
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130506/b3bd2610/attachment.html>


More information about the NumPy-Discussion mailing list