how u can say that??
10,1,90 i got [1,0,2] # indexing in increasing order of no
5,108,72 i tgot [0,2,1]
78,98,2 i want [1,2,0] but i got [2,0,1] # now u urself calculate what u gor accord to incresing order of no sir.
[10, 1, 90] -> index: [1, 0, 2], as this will result in: [1, 10, 90]
[5, 108, 72] -> index: [0, 2, 1], as this will result in: [5, 72, 108]
[78, 98, 2] -> index: [2, 0, 1], as this will result in: [2, 78, 98]
Why and how should the last index be [1, 2, 0]? This would result in [98, 2, 78].
woooww greatt
u kidding me sir
do u know what ““agrsort”” do actually??
lets take 1 instead o 5 in 2nd column ,it doesnot effect the output 1 is alsi less than => 108,72
[1,108,72] so according to ur logic it may be [1,2,0] but output is [0,2,1]
means ur logic is failed sir
first undesrstand what “argsort” do then make ur logic sir
thank you
Dear brother @AnilNITT ,
if u would have known what argsort does you would have understood, after these many explanations atleast. Your mindset is wrong.
dim=1 means row-wise argument sort
can u explain me how u got [2,0,3,1] for 1st row [ 0.0785, 1.5267, -0.8521, 0.4065] ???
bcoz we given index according to increasing order value in all other rows.
if u explain it i got my question answer too bro @Prashant_Kalikotay @ptrblck@tancl@SimonW
Like @ptrblck, I think taking a step back and noticing that no less than four kind people have been going out of their way trying to help might be useful. Keeping things friendly seems not only nice but also essential to your cause and the forums in general.
My impression is that the confusion is between the permutation mapping unordered to ordered (returned by argsort) and the inverse, mapping ordered to unordered.
In the 2d case, you can invert the permutation using scatter (in 1d, indexed assignment c[b] = torch.arange(...) is quicker and more obvious) if you need the inverse.
a = torch.randn(4,4)
b = a.argsort(dim=1)
c = torch.scatter(torch.zeros_like(b), 1, b, torch.arange(b.size(1))[None, :].expand_as(b))
# check that c is the inverse of b
print(b.gather(1, c))
# c, the inverse permutation of what argsort returns, probably is what you are looking for
print(c)
# or you can get the sorted values and rearrange to match the original using the inverse permutation
print((a.gather(1, b)==a.sort(1).values).all().item())
print(((a.sort(1).values).gather(1, c)==a).all().item())