I don’t think the issue is due to this function. I got the same output when running this function. You can make the function shorter.
def calc_weights(cat0_num, cat1_num, cat2_num, cat3_num, cat4_num):
    catnum = np.array([cat0_num, cat1_num, cat2_num, cat3_num, cat4_num], dtype=np.float32)
    catnum = (catnum.sum()/catnum).round(5)
    catnum = torch.from_numpy(catnum)
    return catnum