-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
DataArray.argsort should be deleted #1635
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
Comments
It seems like another reasonable choice would be for I think this internal utility function is equivalent to your second argsort: Lines 38 to 55 in 2949558
In practice, we might use |
I think that makes sense, though I don't quite understand what would go in its place. Another possibility -- perhaps a bad one -- is to permute the values in the sorted dimension so that they match the resulting values (i.e. something like Note that Alternative suggestion: have
BTW, I'm just thinking in terms of |
I'm not a huge fan of auto-flattening for xarray, but I can see this logic.
I would probably implement a new method for this, maybe |
I'm not a fan of auto-flattening either, but that's what One option is to have |
In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity If this issue remains relevant, please comment here or remove the |
I think this issue is still relevant. |
I agree that at least the index should show the reflect the order of the ranking found using argsort. import xarray as xr
import numpy as np
np.random.rand(10)
ds = xr.DataArray(np.random.rand(10) )
ds.argsort().dim_0 returns however it should return an array with the order of the elements ranked using argsort
Where ds[3] is the smallest value in ds and ds[0] is the biggest etc. The current behaviour is confusing / nonsenical. Return the index unchanged implies that the initial array is already ordered.
|
Originally posted to https://groups.google.com/forum/#!topic/xarray/wsxeiIPLhgM
DataArray.argsort()
appears to simply wrap the result ofDataArray.values.argsort()
in a same-shapeDataArray
. This is semantically nonsensical. If anything the index on the resultingargsort()
values should simply berange(len(da))
, but that adds little to the underlying numpy structure. And there's not much reason to haveda.argsort()
simply return the (raw) result ofda.values.argsort()
. So reallyDataArray.argsort()
should simply be deleted.On the other hand a new function
DataArray.rank()
that wrapsda.values.argsort().argsort()
(note repeated call tondarray.argsort()
) in the structure of the originalDataArray
would make sense, and perhaps even be useful... (Note that I'm not claiming that.argsort().argsort()
is the fastest way to calculate this, but it's probably good enough, at least for an initial implementation.)The text was updated successfully, but these errors were encountered: