[Numpy-discussion] searchsorted descending arrays
ben.root at ou.edu
Tue May 7 09:15:27 EDT 2013
On Mon, May 6, 2013 at 7:16 PM, Nathaniel Smith <njs at pobox.com> wrote:
> On Mon, May 6, 2013 at 6:54 PM, Bago <mrbago at gmail.com> wrote:
> > 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
> > first and last elements. This works pretty well in most cases, but fails
> > one notable case. After giving it some thought, I think the best way to
> > searching of descending arrays to numpy would be by adding a keyword to
> > searchsorted function. I wanted to know what you guys thought of this
> > 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
> > 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
> I agree, that result would not really be acceptable (could easily
> break various algorithms in very hard to notice cases), so a kwarg
> would be better.
+1 on kwarg approach.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion