Solved by albanD in post #5 
              
              
                Hi, 
If you want to change the corners of a square matrix with 4 values, the most efficient way is to change the stride by hand to get the tensor you want: 
import torch

# a must be 2x2
# b can be any squared matrix
# You can generalize to batch by keeping original size and stride below
a = torch.r…