Table of Contents
Shortcuts

# torch.flip

torch.flip(input, dims) → Tensor

  Reverse the order of an n-D tensor along given axis in dims.

  Note

  torch.flip makes a copy of `input`’s data. This is different from NumPy’s np.flip, which returns a view in constant time. Since copying a tensor’s data is more work than viewing that data, torch.flip is expected to be slower than np.flip.

  Parameters:

    - input (Tensor) – the input tensor.

    - dims (a list or tuple) – axis to flip on

  Example:

      >>> x = torch.arange(8).view(2, 2, 2)
      >>> x
      tensor([[[ 0,  1],
               [ 2,  3]],

              [[ 4,  5],
               [ 6,  7]]])
      >>> torch.flip(x, [0, 1])
      tensor([[[ 6,  7],
               [ 4,  5]],

              [[ 2,  3],
               [ 0,  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.