Thanks for the example, super helpful!  Here’s some syntactic sugar (or how you’d wanna call it):



 ptrblck:

class_sample_count = np.array(
[len(np.where(target == t)[0]) for t in np.unique(target)])


Suggestion:
class_sample_count = np.unique(target, return_counts=True)[1]




 ptrblck:

samples_weight = np.array([weight[t] for t in target])


Suggestion:
samples_weight = weight[target]




 ptrblck:

samples_weigth = samples_weight.double()


Casting to double is not needed anymore, and probably wasn’t three months ago considering the typo.