Getting the index of successive minimum comparisons
Say if i have a tensor

values = torch.tensor([5., 4., 8., 3.])


and i want to take the minimum over every 2 successive values, meaning

min(5., 4.) = 4.
min(8., 3.) = 3.


is there a vectorized way of doing it and still obtaining back the relative index of the minimum? Meaning what I want as output is:

min_index = [1, 1]
#min_index[0] == 1 as 4. is the minimum of (5., 4.) and is in index 1 of (5., 4.)
#min_index[1] == 1 as 3. is the minimum of (8., 3.) and is in index 1 of (8., 3.) 


I think reshaping your tensor will make it a lot easier.
After that the torch.min automatically returns the minimum values and indexes.

import torch

values = torch.tensor([5., 4., 8., 3.])
values_reshaped = values.reshape(-1,2) # works for any length
minimums, index = torch.min(values_reshaped, axis = -1)
print(minimums) # tensor of the minimum values
print(index) # tensor of indexes

