I’m looking for a built in function in python that applies a function to each element and the next element within a list (or other iterable), returning the set of results in a new list. I don’t know if one is built in or not, but I’m attempting to approach this in a functional way if possible.
Example:
l = [1,2,3,4,5]
# returns [3,5,7,9]
# add(1,2) add(2,3) add(3,4) add(4,5)
My actual use case is that I have a list of vectors of the form numpy.array([1,2,3]), and I want to find the difference between each successive vector.
Actual example:
l = [numpy.array([1,2,3]), numpy.array([2,7,6]), numpy.array([4,5,6])]
# find the difference between each vector (l[0]-l[1], l[1]-[l2], .. etc)
You want
pairwise()andmap().