Hihi Hoho!



 hohohihi:

previous try
I try { mask.repeat(0,0,1,0) *(element-wise mul) x } and do the max operation. But, ‘0’ might the max value, because the x might have minus values in all array. So, this would result in wrong operation.


Rather than use multiplication to set your masked elements to zero
(which, as you note, will be incorrect), use subtraction to set your
masked values to a large negative value.
Please see this “masked argmax” post:

  
    
    
    Masked argmax in Pytorch? 
  
  
    Hello Dragon! 

This won’t work if tensor t is negative (or, more precisely, if its 
largest unmasked element is negative). 
I would do this: 
large = torch.finfo (t.dtype).max   # assumes t is a kind of float
# assume msk has zeros where elements t should be masked out
# and ones where they should be kept
(t - large * (1 - msk) - large * (1 - msk)).argmax()

Best. 
K. Frank
  


Best.
K. Frank