I think what you mean - in PyTorch notation - is a kernel size of 3 and a stride of 1. You can use torch.nn.AvgPool1d
to perform this kind of operation:
mean = nn.AvgPool1d(kernel_size=3, stride=1)
Note, you will need one extra dimension, for the channel, to be compatible with this kind of layer:
>>> x = torch.tensor([[1, 2, 3, 4, 5]]).unsqueeze(0)
tensor([[[1, 2, 3, 4, 5]]])
>>> mean(x)
tensor([[[2, 3, 4]]])
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…