Get the mean of 1D tensor for every value

For example, I have 2 tensors below:
a = tensor([[ 4.0155, 3.4703, 4.1574, 3.6536, 3.0531]])
b = tensor([[ 1.0568, 3.8943, -0.1209, 0.6889, 0.3717]])

result:

c = tensor([[ mean(4.0155, 1.0568) , mean(3.4703, 3.8943), mean(4.1574, -0.1209), mean(3.6536, 0.6889), mean(3.0531,0.3717)]])

This should work:

a = torch.tensor([[ 4.0155, 3.4703, 4.1574, 3.6536, 3.0531]])
b = torch.tensor([[ 1.0568, 3.8943, -0.1209, 0.6889, 0.3717]])

c = torch.cat((a, b), dim=0)
c.mean(dim=0)
# tensor([2.5361, 3.6823, 2.0182, 2.1712, 1.7124])
1 Like