First I generated a random 1d array x,
then I generated array y by swapping elements of x.
Now y is a permutation of x, in principle, if
I apply numpy argsort, I should get different results, as it turned out,
it was not the case.
Here are my python codes,
import numpy as np
x = np.random.random(10)
print(x)
y = x
y[0], y[1] = x[1], x[0]
y[3], y[4] = x[4], x[3]
print(y)
Then I got
[ 0.818 0.99 0.291 0.608 0.773 0.232 0.041 0.136 0.645 0.94 ]
[ 0.99 0.818 0.291 0.773 0.608 0.232 0.041 0.136 0.645 0.94 ]
Now
print(np.argsort(x))
print(np.argsort(y))
I got
[6 7 5 2 4 8 3 1 9 0]
[6 7 5 2 4 8 3 1 9 0]
y = x[:]should worky = x[:]is the same asy=xy = x[:]is likey = x.copy()x[:]will only have a chance at working for 1D arrays. Second,x[:]creates a view in numpy. I think that this can create a copy under some circumstances, but it frequently doesn't. . .