On Mon, May 6, 2013 at 7:16 PM, Nathaniel Smith <n...@pobox.com> wrote:
> On Mon, May 6, 2013 at 6:54 PM, Bago <mrb...@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 > 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 > > 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. > > -n > +1 on kwarg approach.
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion