def normalize(lx):
lx = numpy.asarray(lx)<EOL>base = lx.max()<EOL>x = numpy.exp(lx - base)<EOL>result = x / x.sum()<EOL>conventional = (numpy.exp(lx) / numpy.exp(lx).sum())<EOL>assert similar(result, conventional)<EOL>return result<EOL>
Accepts log-values as input, exponentiates them,
normalizes and returns the result.
Handles underflow by rescaling so that the largest values is exactly 1.0.