Get mean squared error between every element in two tensors
I have two single dimensional tensors, y_pred and y_true
where:
&gt;&gt;&gt; y_pred.shape
torch.Size([2730441, 1])
&gt;&gt;&gt; y_true.shape
torch.Size([2730441, 1])

To get the Mean Squared Error between the two tensors I can use
torch.nn.MSELoss() However, I want to get the loss between each row/ element in the tensors y_pred &amp; y_true i.e. I want to run some function elementWiseMSE(y_pred, y_true) which will return loss_tensor of shape [2730441, 1] which contains the elementwise mean error of all the predictions.

The &quot;function&quot; you are looking for is literally
loss_tensor = (y_pred - y_true) ** 2

