Every line of 'pytorch argmax' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
104 def argmax(x): # return the one-hot vectors 105 shape = x.size() 106 _, ind = x.max(dim=-1) 107 x_hard = Variable(x.data.new(x.size()).zero_().view(-1, shape[-1])) 108 x_hard.scatter_(1, ind.view(-1, 1), 1) 109 x_hard = x_hard.view(*shape) 110 return x_hard
67 @staticmethod 68 def forward(ctx, input): 69 _, max_index = input.max(1) # N 70 output = input.clone().zero_() # N * K 71 return output.scatter_(1, max_index.unsqueeze(1), 1)