-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
error in np.lexsort axis kwarg #10521
Comments
Not sure, but may be related to #5782. Lexsort could use a serious rehaul... |
The documentation is confusing, indeed, deceptive. The axis is for the case when each key is an array, in which case it the axis is taken from that array. I think the logic in the relevant function,
Not sure why the result has that shape, but frankly, I have no idea what the intended use of that keyword is :( |
Apropos the current problem, this may be what you want
Note that you probably need to remove the first dimension of the result. |
And whatever is intended, I think it is buggy. |
The syntax
Ok it sorts by first column, but then it forgets the second! Actually, it gives the same result as To sort according to columns, the easy way is to translate, but I do not understand either why the sorting order is second then first line (hence the [::-1])
I would expect |
I just ran into this while poking >>> np.lexsort(np.arange(2*3).reshape(2, 3), axis=-1) # default axis
array([0, 1, 2])
>>> np.lexsort(np.arange(2*3).reshape(2, 3), axis=1) # 1 is -1 in case of 2d, right?
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<__array_function__ internals>", line 5, in lexsort
numpy.AxisError: axis 1 is out of bounds for array of dimension 1 I now understand that I haven't checked the blame in these past 3 years but the docstring is still confusing. There's no mention of the Should we try clarifying the docs? Looking at the above comments I'm not even sure the behaviour is always as expected? It would also be nice to be able to give a better error message, but I suspect that might need too much special-casing in the implementation (if I'm reading it correctly we'd have to patch somewhere around here). |
apparently this is still a problem |
Hello,
I would like to sort an array according to lexical order, sorting by first the second column. np.lexsort is the function to use, but it seems not to handle the kwarg axis.
>>> import numpy as np
>>> a = np.array([[0,1],[1,0],[0,0],[0,-1],[0,1],[1,-1]])
>>> a.ndim
2
>>> np.lexsort(a.T,axis=1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: axis(=1) out of bounds
Info version :
Debian Python 3.5.
>>> np.__version__
'1.12.1'
The same bug happens with Anaconda python and numpy.
The function
np.argsort
does not suffer from this problem, but is not what I want. In my case, I could usenp.lexsort(a.T[::-1])
as a workaround.The text was updated successfully, but these errors were encountered: