3
$\begingroup$

This may be a simple question. Please close it if it is already answered.

I have a nested list

kr = {{35, 32, 27, 20}, {36, 33, 28, 21}, {37, 34, 29, 22}} 

I want to use a function flo[x_,y_,z_] on each of the lists after modifying it. So the Mapthread on a given list k0 (eg. {35, 32, 27, 20}) will look like this

MapThread[flo[L, ##] &, {Most@k0, Rest@k0}];

I want the output to look like this.

qfr = {{flo[L,35,32], flo[L,32,27],flo[L,27,20]},{flo[L,36,33], 
           flo[L,33,28],flo[L,28,21]},{flo[L,37,34], flo[L,34,29],flo[L,29,22]}}

I tried to do the following without much luck. what am I missing?

MapThread[flo[L, ##] &, {Most@#, Rest@#}] & kr
$\endgroup$
  • 2
    $\begingroup$ You're almost there... you just need to Map it on to kr like this: MapThread[flo[L, ##] &, {Most@#, Rest@#}] & /@ kr $\endgroup$ – rm -rf Mar 12 '14 at 14:37
3
$\begingroup$

What about

flo[L, ##] & @@@ Partition[#, 2, 1] & /@ kr

Regarding your initial try, this would work:

MapThread[flo[L, ##] &, {Most@#, Rest@#}] & /@ kr

Without the /@ you are multiplying the expression MapThread[flo[L, ##] &, {Most@#, Rest@#}] & with every element in kr. The /@ on the opposite uses the expression as a function and applies it to every element in kr treated as a list.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.