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
Sorting should work for array scalars. #7051
Comments
@charris Checking if not a.ndim:
a = asanyarray([a])
a.sort(axis, kind, order)
return a Probably, doing just that won't help because we'll still get ValueError in case of #define PyArray_Sort (*(int (*)(PyArrayObject *, int, NPY_SORTKIND)) PyArray_API[129]) As I am a beginner I might be missing something here. Could you please let me know where |
The base sort is an array method, so that is what we want fixed. |
I agree that it is silly that this exists and does not work, but on the other hand the default for the sort is axis=-1, which is correctly an error for 0-d arrays unlike most similar methods which use axis=None (unsupported currently in sort) where this is no problem. |
I ran into this because of an argument that could be either a list or a scalar and I wanted to preserve that distinction while also sorting the result of asarray. So in that case it would avoid special casing. |
Do we want to fix this for the Python API only, or for On a related note, is this behavior correct, or should the return also be an array scalar? >>> np.argsort(np.array(8))
array([0]) |
I'm not sure that this does make sense... sorting needs a dimension to
|
@njsmith Array scalars can be operated on inplace. I guess I'm looking at 0-D arrays as containers rather than scalars even if they can't be indexed with integers. |
Mind, i'd just like the operation to be a NOP rather than an error. |
I'm just saying that sorting is an intrinsically one-dimensional operation
|
Just return the array, don't error.
The text was updated successfully, but these errors were encountered: