Home > database >  Get mean squared error between every element in two tensors
Get mean squared error between every element in two tensors

Time:03-20

I have two single dimensional tensors, y_pred and y_true where:

>>> 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.

CodePudding user response:

The "function" you are looking for is literally

loss_tensor = (y_pred - y_true) ** 2
  • Related