How to do mean variance normalize in loss function

Hi,all
I want know how can I do mean-variance normalization when I calculate the loss?
I try to convert the tensor to a numpy array ,and convert the array back to tensor after normalize in loss function. but it will cause some problem when I use loss.backward() ,so I don’t know how to do that.

Thanks in advance

Could you post the numpy code you are using to perform the operation?
If you can re-write it in PyTorch, your code should work fine.