Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

sorting a tensor with the indices from argsort - is there a symbol operator? #21201

Closed Answered by mureva
mureva asked this question in Q&A
Discussion options

You must be logged in to vote

OK, so gather_nd can do it - but we need a fair bit of manipulation.
pseudocode:

i0 = argsort(A, axis=1)     // gives (bs,s,1)
i1 = transpose( i0, (2,0,1) // gives (1,bs,s)

ls0 = linspace(0,bs-1,bs)       // gives integer indices 0->(bs-1)
ls1 = reshape(ls0, (1,bs,1))
ls2 = broadcast_to(ls1, (1,bs,s))

inds = concat( {ls0,i1}, axis=0 )  // gives (2,bs,s)

sortedB = gather_nd( B, inds )

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by mureva
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant