Since non-normalized `hist` is not used again, you can do inplace division here and save some memory `hist /= hist.sum()`