Hi Pytorch Community
I have a tensor of shape (6, 3, 5, 5) and for my project i want to keep a fraction 0 < q < 1 of indices that are related to the q largest elements in that tensor and set the others to zero. Let me show you an example of what i am exactly talking about in a smaller measure. Assume that i have a tensor of shape (2, 2) like below:

a = [[1 ,3], [4, 2]]

Now imagine that i want to keep 50 percent of all the elements in this tensor. But those 50 percent have to be the largest ones among them so the final result will be like:

b = [[0, 3], [4, 0]]

I will appreciate if you can give me a hint or a solution on how to do this.
Thank you