def lnsum0(lx):
 lx = numpy.asarray(lx)
 base = lx.max()
 x = numpy.exp((lx - base))
 ssum = x.sum(0)
 normalized = nsum0(lx)
 result = numpy.log(normalized)
 conventional = numpy.log((numpy.exp(lx).sum(0) / numpy.exp(lx).sum()))
 assert similar(result, conventional)
 return result

def lnsum0 ( lx ) : lx = numpy . asarray ( lx ) base = lx . max ( ) x = numpy . exp ( ( lx - base ) ) ssum = x . sum ( 0 ) normalized = nsum0 ( lx ) result = numpy . log ( normalized ) conventional = numpy . log ( ( numpy . exp ( lx ) . sum ( 0 ) / numpy . exp ( lx ) . sum ( ) ) ) assert similar ( result , conventional ) return result
accepts log-values as input .