Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Wrong result of argsort for unsorted negative values #17561

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
zxdawn opened this issue Oct 14, 2020 · 1 comment
Closed

Wrong result of argsort for unsorted negative values #17561

zxdawn opened this issue Oct 14, 2020 · 1 comment

Comments

@zxdawn
Copy link

zxdawn commented Oct 14, 2020

Reproducing code example:

import numpy as np

a = np.array([-9.93686340e+02, -9.85949280e+02, -9.67635925e+02, -9.39872864e+02,
              -8.98984009e+02, -8.41368530e+02, -7.81853699e+02, -6.92064392e+02,
              -6.12045349e+02, -5.30710449e+02, -4.54482269e+02, -3.71461731e+02,
              -3.14179626e+02, -2.76059692e+02, -2.41759018e+02, -2.20870255e+02,
              -1.92301758e+02, -1.66814026e+02, -1.44157349e+02, -1.30507690e+02,
              -1.12051003e+02, -9.58245697e+01, -8.61438751e+01, -7.31186905e+01,
              -6.15607414e+01, -4.49081726e+01, -3.38174362e+01, -2.26543159e+01,
              -1.42377014e+01, -8.23967838e+00, -4.27592516e+00, -1.91338563e+00,
              -6.95205748e-01, -1.86089307e-01, -0.00000000e+00,
              -9.93686328e+02, -7.39944519e+02])

print(np.argsort(a))

Error message:

[ 0 35  1  2  3  4  5  6 36  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21
 22 23 24 25 26 27 28 29 30 31 32 33 34]

The result should be:

[ 0  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21
 22 24 25 26 27 28 29 30 31 32 1 23]

Note that a[:-2] is ascending (print(np.argsort(a[:-2]))):

[ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 24 25 26 27 28 29 30 31 32 33 34]

The last two elements cause the bug above.

NumPy/Python version information:

1.19.1 3.8.5 | packaged by conda-forge | (default, Jul 24 2020, 01:25:15) 
[GCC 7.5.0]
@eric-wieser
Copy link
Member

eric-wieser commented Oct 14, 2020

Duplicate of #8757

@eric-wieser eric-wieser marked this as a duplicate of #8757 Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants