I would like to see how numpy.argsort()
works.
In the documentation, the source for
numpy.argsort()
isnumpy.core.fromnumeric.py
. This is understandable. https://numpy.org/doc/stable/reference/generated/numpy.argsort.htmlcore.fromnumeric.argsort()
is a bit more complicated.
Ignoring decorators, iffromnumeric.argsort(arr)
returns_wrapfunc(arr, "argsort")
, which returnsarr.argsort()
. This is not a problem.
Assumingarr
isnumpy.ndarray
, it might be inarray_api.__init__.py
. https://github.com/numpy/numpy/blob/v1.21.0/numpy/core/fromnumeric.pyarray_api.argsort()
is fromarray_api._sorting_functions.argsort()
. OK.https://github.com/numpy/numpy/blob/main/numpy/array_api/__init__.py_sorting_functions.argsort()
callsnumpy.argsort()
. That is what I was looking for at first. It is circular. https://github.com/numpy/numpy/blob/main/numpy/array_api/_sorting_functions.py
Extra
In
numpy.__init__.pyi
,numpy.argsort()
is fromcore.fromnumeric
https://github.com/numpy/numpy/blob/main/numpy/__init__.pyi1.
and5.
are the same thing.
Are these circular references? Of course I know these work. Is it might be in array_api.__init__.py.
in 2.
wrong? So where is the actual location of its implementation?
Background on this issue
I noticed that np.unique
is slow when return_index=True
. I wanted to run np.unique
on the sorted array, but found that np.unique
calls np.argsort
. So I tried to find out the difference between np.argsort
and np.sort
and needed to know more about np.argsort
.
1. Is single-axis array also multiarray? 2. How is `numpy.argsort` related to those C codes?(This is the question about the basics of the NumPy and out of the scope of the original question) – Azriel 1rf Oct 28 '21 at 03:39