I’ve got a batch of real numbers and list of values representing bins. I want to find the closest matching bin value for each real number, and convert that real number into a one-hot vector for that bin (resulting in a batch of one-hot vectors). I want to be able to do this on the fly (i.e. not preprocess the real values into one-hot vectors before training). If this were in NumPy, I would use something like searchsorted (since the bin value vector is already sorted). Unfortunately, PyTorch doesn’t seem to have an equivalent function yet. I can use a broadcasted version of something like this answer on SO 19, but this assumes no sorting, and probably will take much longer to run than is necessary. Any thoughts on a better alternative? Thanks!