Replace sum calls to np.sum function for performances improvement