I need to pad a 3x3 tensor on all sides with some random values sampled from either the tensor itself or from a distribution. So, a 2d tensor
1 2 3
4 5 6
7 8 9
after padding becomes
4 1 2 2 3
1 1 2 3 2
1 4 5 6 4
3 7 8 9 2
2 2 1 3 3
or
0.22 0.55 0.91 0.11 0.65
0.01 1 2 3 0.99
0.23 4 5 6 0.37
0.43 7 8 9 0.41
0.89 0.13 0.25 0.71 0.93
Is there any way to do this in pytorch?