Hi,
Short answer is no, if you look at this as a mathematical function, it is constant almost everywhere and so will just have a 0 gradient.
I am not sure what multiplying the values by the locations is doing, but that does not look like it’s doing what you want.
This is exactly why we use cross entropy loss for classification for example. Otherwise, we could just argmax the output of the network and check if it matches or not the ground truth label.