1
$\begingroup$

I am trying to write a function that takes 3 tuples. Each tuple contains two lists which are first divided. This results in 3 lists. Then I want to take the Mean of all the columns. I can do this in two steps:

d = Divide[#1, #2] & @@@  { {{1, 2, 3}, {4, 5, 6}}  , {{7, 8, 9}, {10,
  11, 12}} , {{13, 14, 15}, {16, 17, 18} } }
Mean[d]

However I would like to put this all on one line. I have tried a couple different things all smilar to

Mean[#] & @ Divide[#1, #2] & @@@  { {{1, 2, 3}, {4, 5, 6}}  , {{7, 8, 9}, {10,
  11, 12}} , {{13, 14, 15}, {16, 17, 18} } }

The problem is the mean is not applied to the entire list but rather one level inside, which does not give the desired output.

the desired out put is:

{47/80, 608/935, 25/36}
$\endgroup$
4
$\begingroup$
list = {{{1, 2, 3}, {4, 5, 6}}, {{7, 8, 9}, {10, 11, 12}}, {{13, 14, 
     15}, {16, 17, 18}}};

Mean[Divide @@@ #] &@ list

Composition[Mean, Divide @@@ # &]@list

Divide @@@ list // Mean

Mean[Divide @@@ list]

Mean @ (Divide @@@ list)

It seems that first and the second may be considered the best since you don't have to put anything after the list.

Take a look at the topic I've linked too.

$\endgroup$
  • $\begingroup$ Aesthetically, the last one is the nicest. $\endgroup$ – eldo May 22 '14 at 19:08

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.