Diffrences in tensor indexing?


I have a quick question about how tensor elements are accessed.

What would be the difference between:

c = x[a][b]


c = x[a, b]

Does the first way create an intermediate tensor and then index that? Or are these functionally identical?



Assuming both a and b are integers:
Yes the first one uses the method to index a single dimension twice with a temporary Tensor in the middle.
The second one calls the general indexing method that will handle this call in one go.

If they are Tensors or iterables, the story is a bit different as each indexing is advanced indexing but it will create a temporary Tensor either way.


Right, makes sense. Thank you!