WebJul 12, 2024 · [feature request] add torch.find to find the indices of values #9413 Closed zasdfgbnm opened this issue on Jul 12, 2024 · 6 comments Collaborator zasdfgbnm on Jul 12, 2024 zasdfgbnm closed this as completed on Apr 6, 2024 guidopetri mentioned this issue on Jul 18, 2024 Connect4 Initial Implementation AlphaZeroIncubator/AlphaZero#36 WebMar 10, 2024 · If you just want the max value, then torch.max will do the trick. If you specify the dimension over which to take the max, then it returns two tensors, the max values and their indices. maxes, indices = torch.max (my_tensor, dim=0)
Every Index based Operation you’ll ever need in Pytorch
WebFeb 14, 2024 · 1 Answer Sorted by: 3 Use argmax with desired dim (a.k.a. axis) a = tensor ( [ [0.3232, -0.2321, 0.2332, -0.1231, 0.2435, 0.6728], [0.2323, -0.1231, -0.5321, -0.1452, 0.5435, 0.1722], [0.9823, -0.1321, -0.6433, 0.1231, 0.023, 0.0711]] ) a.argmax (1) # tensor ( [ 5, 4, 0]) Share Improve this answer Follow answered Feb 14, 2024 at 1:12 Chris WebJan 27, 2024 · To find the indices of the maximum value of the elements in an input tensor, we can apply the torch.argmax () function. It returns the indices only, not the element value. If the input tensor has multiple maximal values, then the function will return the index of the first maximal element. robert day college park
Understanding indexing with pytorch gather by Mateusz …
WebJul 10, 2024 · python pytorch 102,591 Solution 1 I think there is no direct translation from list.index () to a pytorch function. However, you can achieve similar results using … WebOct 26, 2024 · def get_index (host, target): diff = target.unsqueeze (1) - host.unsqueeze (0) dsum = torch.abs (diff).sum (-1) loc = (dsum == 0).nonzero () return loc [:, -1] for example I wanted to extract the index from 2D Tensor of shape (40,2). Such that Target [:,1] = 0 and 1 . This is the result I got: WebMar 22, 2024 · index — tensor with indices of values to collect Important consideration is, dimensionality of input and index has to be the same except in dim dimension. For example, if input is 4x10x15 and... robert day developer