I was looking at torch.split() and apparently it splits a tensor into chunks along a given dimension, so if I do

a = torch.tensor([1,2])
torch.split(a, 2, 1)

it gives me an error that says IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1).

How can dimension be negative? I thought dimension here means 2-> 0 dimension, [1,2] -> 1 dimension, how ever many [] how ever many dimensions there are. What is this -1 dimension doing here and how does that make sense in the example of torch.split()?

A 1D tensor will have 1 dimension but it’ll be numbered from 0 i.e 0th dimension, similarly a 2D tensor will have 0th and 1st dimensions as 2 dimensions. (As per your example which is 1D tensor will accept only -1 or 0 as values for dim arg)

You can use .shape and .ndim when you checking for the size and no. of dimensions