How to use 'pytorch argmax' in Python

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.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
104def 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
68def 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)

Related snippets