I need function-aggregator, which would reduce two lists to one total number. ‘Items’ is supposed to be vector of Booleans.
So, I wrote these functions:
def element_wise_multiplication(weights, items):
return map(lambda x, y: x * y, weights, items)
def total(weights, items):
return sum(element_wise_multiplication(weights, items))
They look OK to me, but the problem is that profiler showed that the line with lambda in it is responsible for 95% of runtime, so its performance is pretty much unacceptable.
What is the most efficient way to implement it?
P.S. I am aware of NumPy’s arrays, but I would like to use PyPy on this one. Or is using it not worth it in this case?
You can take care of that with a generator like so:
izipaccomplishes the same thing as the built-inzip, but without the memory overhead.