Table of Contents
Shortcuts

# torch.Tensor.stride

Tensor.stride(dim) → tuple or int

  Returns the stride of `self` tensor.

  Stride is the jump necessary to go from one element to the next one in the specified dimension `dim`. A tuple of all strides is returned when no argument is passed in. Otherwise, an integer value is returned as the stride in the particular dimension `dim`.

  Parameters:

    dim (int, optional) – the desired dimension in which stride is required

  Example:

      >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
      >>> x.stride()
      (5, 1)
      >>> x.stride(0)
      5
      >>> x.stride(-1)
      1

## Docs

Access comprehensive developer documentation for PyTorch

View Docs

## Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

## Resources

Find development resources and get your questions answered

View Resources

To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.