Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add unyt_array.argsort. Fixes #51 #52

Merged
merged 3 commits into from
Sep 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions unyt/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,24 @@ def to_ndarray(self):
"""
return np.array(self)

def argsort(self, axis=-1, kind='quicksort', order=None):
"""
Returns the indices that would sort the array.

See the documentation of ndarray.argsort for details about the keyword
arguments.

Example
-------
>>> from unyt import km
>>> data = [3, 8, 7]*km
>>> print(np.argsort(data))
[0 2 1]
>>> print(data.argsort())
[0 2 1]
"""
return self.view(np.ndarray).argsort(axis, kind, order)

@classmethod
def from_astropy(cls, arr, unit_registry=None):
"""
Expand Down