Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

A simple problem I am facing is here:

list1 = RandomReal[{1, 2}, {3, 4, 30}];
list2 = RandomReal[{10, 20}, {3, 4, 30}];
Map[Map[(# + 1+Min[#]) &, #] &, #] &/@list1;

works fine, but whenever such a nested Map appears, I think there might be a better solution than what I am doing here. Now my problem is if I want to use a MapThread over the above function like the following, I stumble upon errors

MapThread[Map[Map[(# + 1/Min[#2]) &, #] &, #1] &, {list1, list2}];

Including this example and for even more nested situations, is there any general coding practice that is elegant, efficient and native to MMA functional language paradigm. Hope some one can help me with this type list manipulation here.

share|improve this question
in your first example list2, does not do much. Could you provide a simple example of the result you'd like. – user21 Mar 22 '12 at 11:21
@ruebenko I dont expect any special result. I just used this example to highlight the situation one faces when using nested Map and question is if there is a way to use MapThread over such nested Map. Feel free to modify the question if you get a better example to make the list2 important for the outer MapThread. – PlatoManiac Mar 22 '12 at 11:28
I think the problem is not nested map, but nested pure functions with &. Try using Function as @ruebenko answer. – FJRA Mar 22 '12 at 13:03

I am not exactly sure what you are looking for so, here are two ideas:

 f[#1, #2] &, {Map[Map[(# + 1/Min[#]) &, #] &, #] & /@ list1, list2}]


 Function[{x, y}, Map[Map[(# + 1/Min[y]) &, #] &, x]], {list1, list2}]

Hope this helps.

share|improve this answer
Using Function is the best option to see if every thing is applied when you want. – FJRA Mar 22 '12 at 13:02

You can supply a third argument to Map and MapThread to indicate at which level in the array the function should be applied. For example for you nested Map example you could do something like

Map[(# + 1 + Min[#]) &, list1, {3}]

For the MapThread example you could do something similar, e.g.

MapThread[(# + 1/Min[#2]) &, {list1, list2}, 3]

would apply the function in the first argument to elements in list1 and list2 at level 3.

share|improve this answer

Your Answer


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.