[SOLVED] Get mean squared error between every element in two tensors


I have two single dimensional tensors, y_pred and y_true

>>> y_pred.shape
torch.Size([2730441, 1])
>>> 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 & 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 "function" you are looking for is literally

loss_tensor = (y_pred - y_true) ** 2

Answered By – lejlot

Answer Checked By – Gilberto Lyons (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *