I'm trying to vectorize/broadcast (Not sure what it is called formally) my code in order to make it faster, but I can't quite get it. What I think I should be using is numpy.cumsum (with axis=0) but I don't know how to get it (fast) in the correct array to use it.
What I want with this code is basically the absolute sum of l1 for adding each element from l2 to all numbers in l1. So this gives not one answer, but len(l2) amount of answers. The (non-vectorized) code below give the correct output.
# l1 and l2 are numpy arrays
for i in l2:
l1 += i
answer = numpy.sum(numpy.absolute(l1))
print answer
Can anyone provide an answer or hint?