How to patch or add a tensor to a bigger tensor?

You could just index the bigger tensor and assign the smaller one to these positions:

a = torch.zeros(5, 5)
a[2:, 2:] = torch.ones(3, 3)
4 Likes