What's dim=-1 means

Notice that in PyTorch version, a tensor and index operation could be written like below

tensor_test = torch.randn(1, 27)
tensor_test[:, 5:]

In C++ libtorch version, i noticed that i have to set the dim=-1 in slice function so that i could get the right answer. But i don’t understand what dim=-1 means.

tensor_test = torch::randn({1, 27})
tensor_test.slice(-1, 5, tensor_test.sizes()[1])
1 Like

I assume it has the same meaning as in the Python code, i.e. “negative indexing”.
-1 would thus map to the last dimension, -2 to the preceding one, etc.