Probably a duplicate, but it isn't easy browsing through list-related questions.
I am looking for an elegant way to construct a function that accepts a list of pairs, for example
list1 = {{x1, y1}, {x2, y2}, {x3, y3}};
and returns a list with added elements that are arithmetic means of the neighbouring coordinates.
list2 = Function[list1] = {{x1, y1}, {(x1+x2)/2, (y1+y2)/2}, {x2, y2},
{(x2+x3)/2, (y2+y3)/2}, {x3, y3}};
Any tips would be greatly appreciated.
MovingAverage
andRiffle
. $\endgroup$MovingAverage[Riffle[list1,list1],2]
$\endgroup$Most[Riffle[#, (# + RotateLeft[#])/2]]&
$\endgroup$