[Numpy-discussion] Improving Complex Comparison/Ordering in Numpy
sebastian at sipsolutions.net
Wed Jul 1 21:44:04 EDT 2020
On Wed, 2020-07-01 at 12:48 -0700, Stephan Hoyer wrote:
> On Wed, Jul 1, 2020 at 12:23 PM Sebastian Berg <
> sebastian at sipsolutions.net>
> > This is a WIP, but allows nicely to try out how the new API
> > could/should look like, and see the potential impact to code. The
> > current choice is for:
> > np.sort(arr, keys=(arr.real, arr.image))
> > for example. `keys` is like the `key` argument to pythons sorts,
> > but
> > unlike python sorts is not passed a function but rather a sequence
> > of
> > arrays.
> > Alternative spellings could be `by=...`? Or maybe someone has a
> > different API idea.
> I really like the look of np.sort(arr, by=(arr.real, arr.image)).
> - This avoids adding an extra function sortby into NumPy's API. The
> behavior (by=None) would of course be to sort by the arrays being
> so it's backwards compatible.
> - Calling the new argument "by" instead of "key" avoids confusion
> with the
> behavior of Python's sort/sorted (which take functions instead of
I just noticed that `DataFrame.sort_values()` uses `by=...` with a list
of column names. However, I guess that is fairly compatible with this
> The combination of lexsort() and take_along_axis() makes it possible
> achieve this behavior currently, but it is definitely less clear than
> single function call.
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 833 bytes
Desc: This is a digitally signed message part
More information about the NumPy-Discussion