def lscsum0(lx):
 lx = numpy.asarray(lx)
 bases = lx.max(0)
 x = numpy.exp((lx - bases))
 ssum = x.sum(0)
 result = (numpy.log(ssum) + bases)
 try:
  conventional = numpy.log(numpy.exp(lx).sum(0))
  if (not similar(result, conventional)):
   if (numpy.isinf(conventional).any() and (not numpy.isinf(result).any())):
    pass
   else:
    import sys
    print >>sys.stderr, 'Warning: scaled log sum down axis 0 did not match.'
    print >>sys.stderr, 'Scaled log result:'
    print >>sys.stderr, result
    print >>sys.stderr, 'Conventional result:'
    print >>sys.stderr, conventional
 except FloatingPointError as e:
  pass
 return result

def lscsum0 ( lx ) : lx = numpy . asarray ( lx ) bases = lx . max ( 0 ) x = numpy . exp ( ( lx - bases ) ) ssum = x . sum ( 0 ) result = ( numpy . log ( ssum ) + bases ) try : conventional = numpy . log ( numpy . exp ( lx ) . sum ( 0 ) ) if ( not similar ( result , conventional ) ) : if ( numpy . isinf ( conventional ) . any ( ) and ( not numpy . isinf ( result ) . any ( ) ) ) : pass else : import sys print >> sys . stderr , 'Warning: scaled log sum down axis 0 did not match.' print >> sys . stderr , 'Scaled log result:' print >> sys . stderr , result print >> sys . stderr , 'Conventional result:' print >> sys . stderr , conventional except FloatingPointError as e : pass return result
accepts log-values as input .