# A question about " Tensor.sort() "

I know the basic usage of sort, but now I have a question.

First, I got a tensor like this:
a = torch.tensor([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1])

# torch.Size([57]), It is a one-dimensional tensor

Then, The code operates as follows:
a,idx = a.sort(0,True)

I got the following results
a = tensor([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1])
idx = tensor([36, 35, 40, 39, 38, 37, 42, 44, 34, 33, 32, 31, 41, 29, 43, 51, 50, 55,
54, 53, 52, 28, 45, 49, 48, 47, 46, 30, 0, 7, 6, 11, 10, 9, 8, 13,
15, 5, 4, 3, 2, 12, 1, 14, 22, 21, 26, 25, 24, 23, 27, 16, 20, 19,
18, 17, 56])

IDX is my question, Variable a is a tensor with all 1, But given the meaning of IDX, the variable a is sorted. Why? Thank you very much for your explanation ! ~

As of now, stable sort is not available in pytorch.

Try to use `numpy.sort()` if you require stable sort.

okay, ~ This problem takes me a lot of time, Iâ€™m dealing with some NLP tasks. This method causes an exception in my sequence, but I canâ€™t find the reason. Thank you very much~

~~

In addition to the second floor engineerâ€™s reply, what other peopleâ€™s reference opinions can I learn from?