list comprehension return a list and sum over in loop
Jussi Piitulainen
jpiitula at ling.helsinki.fi
Fri Dec 12 06:12:19 EST 2014
KK Sasa writes:
> def p(x,t,point,z,obs):
> d = x[0]
> tau = [0]+[x[1:point]]
> a = x[point:len(x)]
> at = sum(i*j for i, j in zip(a, t))
> nu = [exp(z[k]*(at-d)-sum(tau[k])) for k in xrange(point)]
> de = sum(nu, axis=0)
> probability = [nu[k]/de for k in xrange(point)]
> return probability[obs]
I must be blind, but this looks like computing a whole probability
distribution and then throwing almost all of it away.
Can't this just return nu[obs]/de?
The expression for tau also seems weird to me. Isn't it equivalent to
[0, x[1:point]], a two-element list with the second element a list?
How can sum(tau[k]) work at all then, for any k > 1?
More information about the Python-list
mailing list