So I have a list like so


and the basic logic I want is to be able to manipulate each of the nested lists individually.

So If I wanted to take the average of each list I would do something like

avglist=Table[(1/3) Sum[list[[n,j]],{j,3}],{n,4}]

But the problem with this is when the program would call list[[1,2]]

So the gist is I am trying to write a program that could average/in general manipulate each of the nested lists of uneven lengths without having to know how many entries are in the list with the most entries.

I can't just add zeroes into the nested lists with fewer entries because if I want to manipulate them first then average it would affect the average.


  • 1
    $\begingroup$ something like Mean /@ list? $\endgroup$ Commented Sep 5, 2014 at 1:10
  • $\begingroup$ Related: (6588), (7924), (28727) $\endgroup$
    – Mr.Wizard
    Commented Sep 28, 2014 at 2:36

1 Answer 1


If in general you want to "do the same thing to each element of a list" then think Map.

list = {{a}, {b, c}, {d, e, f}, {g, h}};
Map[Mean, list]

(* Out[2]= {a, (b + c)/2, 1/3 (d + e + f), (g + h)/2} *)

Replace Mean with a function of your own definition if necessary.

myF[v_] := v.v + Length[v] - First[v];
Map[myF, list]

(* Out[4]= {1 - a + a^2, 2 - b + b^2 + c^2, 3 - d + d^2 + e^2 + f^2, 2 - g + g^2 + h^2} *)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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