import torch # Tensor of interest tens_A = torch.rand((2,3,4)) # 3-dimensional tensor of shape (2,3,4) def test_view(tensor, sizes): try: tensor.view(*sizes) except Exception as e: print(e) print(f"View was Failed: tensor.is_contiguos == {tensor.is_contiguous()}") else: print(f"View was Successful: tensor.is_contiguos == {tensor.is_contiguous()}") sizes = (3,4,2) # Let's try to use view test_view(tens_A, sizes) # Apply view-function that change contiguity and try again perm_tens_A = tens_A.permute(0,2,1) # change order of axis test_view(perm_tens_A, sizes) # this will result in RuntimeError("Use .reshape(...) instead")