Find the nearest value in the list

As the order of array is already ascending, so you can try this:

import torch
val = 0.505
nuclears = [0, 0.1, 0.15, 0.2, 0.3, 0.33, 0.5, 0.51, 0.8, 1]
mat = torch.Tensor(nuclears)
print(mat > val)

mat_tmp = torch.min((mat > val), 0)

print(mat_tmp[1].item() + 1)
1 Like