Pytorch tensor stride - how it works

  1. The stride will have the same number of values as the number of dimensions. E.g. if you are dealing with a tensor with 4 dimensions, tensor.stride() will return 4 values.

  2. Yes, that’s correct and this post gives another example with contiguous vs. non-contiguous tensors.

  3. The stride is used in the backend for indexing, which can be used if you want to directly access specific elements in the memory block.

5 Likes