generate 1D tensor as unique index of rows of an 2D tensor (keeping the order and the original index)
This question is an updated version of generate 1D tensor as unique index of rows of an 2D tensor
Let's say we transform a 2D tensor to a 1D tensor by giving each, different row a different index, from 0
to the number of rows - 1
.
[[1,4],[1,3],[1,2]] -> [0,1,2]
But if there are same rows, we repeat the index, like this below, the "original" index is k-1
for the k
-th row
[[1,4],[1,2],[1,2]] -> [0,1,1]
Also if there is no repeat for the row (like the third row below), its index should be its original index, which is k-1
for the k
-th row (for example 2 for [1,4]).
[[1,3],[1,3],[1,4]] -> [0,0,2]
A longer example:
[[1,2],[4,3],[1,4],[1,4],[4,3],[1,2],[5,6],[7,8]] -> [0,1,2,2,1,0,6,7]
How to implement this on PyTorch?
source https://stackoverflow.com/questions/72689843/generate-1d-tensor-as-unique-index-of-rows-of-an-2d-tensor-keeping-the-order-an
Comments
Post a Comment