1
$\begingroup$

Given a array of lists with the same number of here N = 10 elements:

SuperList = {{5., 4.99667, 4.99335, 4.99002, 4.98669, 4.98337, 4.98004, 4.97671, 4.97338, 4.97006}, {5., 4.99667, 4.99335, 4.99002, 4.98669, 4.98337, 4.98004, 4.97671, 4.97338, 4.97006}, {5., 4.99667, 4.99335, 4.99002, 4.98669, 4.98337, 4.98004, 4.97671, 4.97338, 4.97006}, {5.,4.99667, 4.99335, 4.99002, 4.98669, 4.98337, 4.98004, 4.97671, 4.97338, 4.97006}, {5.1, 5.09667, 5.09335, 5.09002, 5.08669, 5.08337, 5.08004, 5.07671, 5.07338, 5.07006}, {5., 5., 5., 5., 5., 5., 5., 5., 5., 5.}, {5., 5., 5., 5., 5., 5., 5., 5., 5., 5.}, {5., 5., 5., 5., 5., 5., 5., 5., 5., 5.}, {5., 5., 5., 5., 5., 5., 5., 5., 5., 5.}, {5., 4.99667, 4.99335, 4.99002, 4.98669, 4.98337, 4.98004, 4.97671, 4.97338, 4.97006}};

How do I efficiently compute an array, which we'll call "MedianList" of length N where each element in the array is the median or mean of the sublist entries at the same index in the "SuperList"? For example, the first element would be:

MedianList[[1]] = Median[{5., 5., 5., 5., 5.1, 5., 5., 5., 5., 5.}];

The second element would be:

MedianList[[2]] = Median[{4.99667, 4.99667, 4.99667, 4.99667, 5.09667, 5., 5., 5., 5., 4.99667}];

And so forth.

$\endgroup$
7
$\begingroup$

Doesn't Median[SuperList] do just that?

From the documentation:

${\text{Median}}\left(\left\{\left\{x_1,y_1,\ldots \right\},\left\{x_2,y_2,\ldots \right\},\ldots \right\}\right) \text{ gives } \left\{\text{Median}\left[\left\{x_1,x_2,\ldots \right\}\right],\text{Median}\left[\left\{y_1,y_2,\ldots \right\}\right]\right\} \text{. }$

$\endgroup$
  • $\begingroup$ You're right, but I don't really like this - from MMA, not you. I would have done Median/@(Transpose@SuperList). Anyone have any insight as to why Median acts like this? $\endgroup$ – N.J.Evans Oct 27 '15 at 20:51
  • 1
    $\begingroup$ @N.J.Evans: It's consistent with most of the other statistical functions like Mean or Variance, which all treat a 2d array as a list of multivariate data samples. And if you're working with multivariate data, that is very useful. $\endgroup$ – Niki Estner Oct 28 '15 at 7:28

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.