srush / Tensor-Puzzles

Solve puzzles. Improve your pytorch.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hints on 10 (roll)

kshitijsachan opened this issue · comments

I'm not sure how to solve roll. I think I should make a permutation matrix, but I don't know how to make the full permutation matrix in one line? Would appreciate a hint.

There are two ways to do this. One is to create a permutation matrix as you say. The other is to use advanced indexing, and just use the fact that arr[ind_arr] will work even if ind_arr is a tensor.

Ah advanced indexing, of course! Thanks :)