How can I implement such a mapping operation in mathematics

I have a list and an arbitrary function with 4 parameters, say {1, 11, 3, 13, 9, 0, 12, 7}and f[{x,y,z,w}]={x+y, z+w}. I want to do this in order to form a new list, so that 4 consecutive elements in the original list are evaluated to get a new value as a new component of the list, and the evaluation must be performed at every 2 positions in the original list, in this case the resulting list:

{{12, 16}, {16, 9}, {9, 19}}

Note here 4 and 2 are subject to change. How to do it in Mathematica? I imagine this as something like Map, but not sure how to relate.

+5
source share
2 answers
f[{x_, y_, z_, w_}] = {x + y, z + w};
list = {1, 11, 3, 13, 9, 0, 12, 7};
f /@ Partition[list, 4, 2]
+11
source

Map[f, Partition[...]]: Developer`PartitionMap. , Map[f, Partition[list, n, ...]]. ,

Needs["Developer`"]
f[{x_, y_, z_, w_}] = {x + y, z + w};
list = {1, 11, 3, 13, 9, 0, 12, 7};
PartitionMap[f,list, 4, 2]

, .

+14

All Articles