I have this case where I have a list of lists of lists, and I need to apply a reduce on each of the sub lists of the first list. The reduce function requires 2 parameters, but that 2nd parameter (the list of lists I want to apply the reduce on), is supposed to be from the main list I pass to the map function Consider the snippet below.
reducedLists = map(reduce(lambda first, second : map(operator.add, first,second), XXX), listsToReduce)
I need to know what should be passed in place of XXX
above.
Here listsToReduce
is a list of lists of lists like [[[1,2,3], [3,2,1]],[[1,3,5],[5,3,1]]]
.
I want the final output of the above map and reduce to be 2 lists
[[4,4,4],[6,6,6]]
which is a pairwise sum of the inner list of list passed to the map.
I could not figure how I can model the map and reduce to pass proper parameters to the reduce function.
My ultimate objective is to use Pool.map
from the multiprocessing
package to perform the reduce operations on multiple cores. Any inputs on restructuring the code with this in mind are much appreciated.