GAN Course1 week 4: dim

please need help,

I am not sure to understand the use of dim in torch.norm as well as why it have to be greater than
-1 for the get_score function to be correct.
here is a chunk of my code:

 other_class_penalty = -torch.mean(torch.norm(other_distances, dim = 1))*penalty_weight


I think the answer to your query lies in the official documentation. You can check it out here.

As the documentation says, dim denotes the dimension in which you want to calculate the norm of the given vector. Now, if you are passing -1, in the hope of calculating the norm across all the dimensions, then you should pass in None instead of -1.

Another thing to note is that though -1 specifies all the dimensions, I don’t think it will work with this function. Also, as the documentation says, we should use torch.linalg.norm() instead of torch.norm(), since it is deprecated now. I hope this helps :smile:


1 Like

Thank you @Elemento, I will go through the documentation to understand all the details.

1 Like