def lscsum(lx, epsilon=None):
 lx = numpy.asarray(lx)
 base = lx.max()
 if numpy.isinf(base):
  return base
 if ((epsilon is not None) and (base < epsilon)):
  return epsilon
 x = numpy.exp((lx - base))
 ssum = x.sum()
 result = (numpy.log(ssum) + base)
 return result

def lscsum ( lx , epsilon = None ) : lx = numpy . asarray ( lx ) base = lx . max ( ) if numpy . isinf ( base ) : return base if ( ( epsilon is not None ) and ( base < epsilon ) ) : return epsilon x = numpy . exp ( ( lx - base ) ) ssum = x . sum ( ) result = ( numpy . log ( ssum ) + base ) return result
accepts log-values as input .