# How to get the index of the unique values in the origin tensor

**URL:** <https://discuss.pytorch.org/t/how-to-get-the-index-of-the-unique-values-in-the-origin-tensor/109525>\
**Category:** Uncategorized\
**Created:** [January 21, 2021, 8:02am UTC](https://discuss.pytorch.org/t/how-to-get-the-index-of-the-unique-values-in-the-origin-tensor/109525 "2021-01-21T08:02:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cslxiao](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/cslxiao/32/4507_2.png) [@cslxiao](https://discuss.pytorch.org/u/cslxiao)\
**Post date:** [January 21, 2021, 8:02am UTC](https://discuss.pytorch.org/t/how-to-get-the-index-of-the-unique-values-in-the-origin-tensor/109525/1 "2021-01-21T08:02:45Z")

</div>

for example,

```auto
>>> a = torch.tensor([4, 1, 4, 3, 2, 3], dtype=torch.long)
>>> b,c =torch.unique(a,return_inverse=True)
>>> a
tensor([4, 1, 4, 3, 2, 3])
>>> b
tensor([1, 2, 3, 4])
>>> c
tensor([3, 0, 3, 2, 1, 2])

```

I want to get the index of each value of `b` in `a`  
i.e., `d` such that `a[d]=b`

```auto
>>> d=torch.tensor([1,4,3,0])
>>> a[d]
tensor([1, 2, 3, 4])

```
