Python List Comprehension Setting Local Variable -
i having trouble list comprehension in python
basically have code looks this
output = [] i, num in enumerate(test): loss_ = test_ = else output.append(sum(loss_*test_)/float(sum(loss_)))
how can write using list comprehension such as:
[sum(loss_*test_)/float(sum(loss_))) i, num in enumerate(test)]
however don't know how assign values of loss_
, test_
you can use nested list comprehension define values:
output = [sum(loss_*test_)/float(sum(loss_)) loss_, test_ in ((do something, else) i, num in enumerate(test))]
of course, whether that's more readable question.
Comments
Post a Comment