8000 DOC: argmin, argmax, argort, etc. should link to `np.take_along_axis` in their documentation · Issue #6078 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

DOC: argmin, argmax, argort, etc. should link to np.take_along_axis in their documentation #6078

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

Closed
mhvk opened this issue Jul 14, 2015 · 7 comments · Fixed by #14799
Closed

Comments

@mhvk
Copy link
Contributor
mhvk commented Jul 14, 2015

In #6075, I wondered whether it might be possible to

to have some simple way to use the output of np.arg[min|max|sort] as a proper index (to avoid hackery as in https://github.com/astropy/astropy/blob/master/astropy/time/core.py#L896 -- if there is a simpler way already, let me know!)

and @jaimefrio suggested that it might be simpler to have

a make_me_an_indexing_tuple=False new keyword argument for the argxxx functions?

That indeed seems better, so I'm raising this as a separate issue. The code linked to above could be used as a template on how to generate the index tuple.

@shoyer
Copy link
Member
shoyer commented Jul 17, 2015

Indeed, this problem has also flummoxed me.

Here's the helper function I wrote, which may be slightly more interpretable:

def argsort_indices(a, axis=-1):
    """Like argsort, but returns an index suitable for sorting the
    the original array even if that array is multidimensional
    """
    a = np.asarray(a)
    ind = list(np.ix_(*[np.arange(d) for d in a.shape]))
    ind[axis] = a.argsort(axis)
    return tuple(ind)

@mhvk
Copy link
Contributor Author
mhvk commented Jul 17, 2015

@shoyer - yours is definitely easier to read, in that it leaves the proper shaping to np.ix_... also, it doesn't deal with keepdims, right?

@shoyer
Copy link
Member
shoyer commented Jul 17, 2015

also, it doesn't deal with keepdims, right?

I guess it's less general in that it only works for argsort -- I didn't think about min/max, so I didn't need anything for keepdims.

@ElieGouzien
Copy link
Contributor

I think it would be lot better than today's implementation if the axis=None option returned something equivalent to :

np.unravel_index(np.argsort(a, axis=None), a.shape)

@shoyer
Copy link
Member
shoyer commented May 12, 2017

I think it would be lot better than today's implementation if the axis=None option returned something equivalent to :
np.unravel_index(np.argsort(a, axis=None), a.shape)

As a rule, NumPy doesn't change existing behavior. So this will need to be new API of some sort.

@ElieGouzien
Copy link
Contributor

@shoyer Oh that's true.
I've just submitted a pull request to add my proposition to the doc so that the user can easily find how to retrieve indices.

@seberg
Copy link
Member
seberg commented May 3, 2019

I think this issue is now irrelevant, since we have np.take_along_axis instead, which solves the issue. I will however transform it into a Documentation issue, since those functions should list it under the See Also section at least.

@seberg seberg changed the title Optional output of full fancy index for argmin, argmax, argort? DOC: argmin, argmax, argort, etc. should link to np.take_along_axis in their documentation May 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
0