Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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}
share|improve this question
1  
Try the postfix // operator. So: ... // Mean –  mfvonh May 22 at 18:45
1  
closely related: when is f@g not the same as f[g] –  Kuba May 22 at 18:50

1 Answer 1

up vote 4 down vote accepted
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.

share|improve this answer
    
Aesthetically, the last one is the nicest. –  eldo May 22 at 19:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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