ML Katas

Permute Dimensions Cyclically

easy (<10 mins) einops tensor manipulation
this year by E

Description

Perform a cyclic permutation of the dimensions of a tensor. For a tensor of shape (D1, D2, D3, D4), a cyclic permutation would result in (D4, D1, D2, D3).

Starter Code

import torch
from einops import rearrange

def cyclic_permute(tensor):
    # Your einops code here
    pass

Verification

For an input of shape (10, 20, 30, 40), the output should have the shape (40, 10, 20, 30).