ML Katas

Tile a Tensor

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

Description

Given a tensor, repeat its values along one or more dimensions. For example, given a tensor of shape (H, W), you might want to create a batch of B identical copies, resulting in a shape of (B, H, W).

Starter Code

import torch
from einops import repeat

def tile_tensor(tensor, num_repeats):
    # Your einops code here
    pass

Verification

For an input of shape (224, 224) and num_repeats of 10, the output should have the shape (10, 224, 224).