Faster way to do adding with indexing

Given the following code

o = torch.randn(10,45,5,5)
cut = 15
		
o1 = o[:, :cut,  :-2, :]
o2 = o[:, :cut, 1:-1, :]
o3 = o[:, :cut, 2:  , :]	

result = o1+o2+o3

Is there a faster way to do it?

1 Like