# Applying Map to two disconnected levels

**URL:** <https://community.wolfram.com/t/applying-map-to-two-disconnected-levels/22942>\
**Category:** Questions\
**Created:** [October 9, 2023, 3:48pm UTC](https://community.wolfram.com/t/applying-map-to-two-disconnected-levels/22942 "2023-10-09T15:48:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gerlebacher](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@gerlebacher](https://community.wolfram.com/u/gerlebacher)\
**Post date:** [October 9, 2023, 3:48pm UTC](https://community.wolfram.com/t/applying-map-to-two-disconnected-levels/22942/1 "2023-10-09T15:48:59Z")

</div>

I am want to apply the `Map` function to a nested list, via:  
` Map[f, {{a1, b1}, {a2, b2}, {a3, b3}}, {0, 2}]` and get the result:  
`f[{f[{f[a1], f[b1]}], f[{f[a2], f[b2]}], f[{f[a3], f[b3]}]}]`

However, I want the function `f` to only be applied at levels 0 and level 2. Map is applying `f` on levels 0 to 2. How is this accomplished? The result l want is:  
`f[{ {f[a1], f[b1]}], f[{f[a2], f[b2]}], f[{f[a3], f[b3]} }]`

How can this be done? Given the generality of the software, I assumed this was possible. Thanks.

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [October 9, 2023, 4:53pm UTC](https://community.wolfram.com/t/applying-map-to-two-disconnected-levels/22942/2 "2023-10-09T16:53:03Z")

</div>

It seems that you cannot do it directly with `Map`, but there are workarounds:

```
mat = {{a1, b1}, {a2, b2}, {a3, b3}};
f@Map[f, mat, {2}]
Fold[Map[f, #1, {#2}] &, mat, {2, 0}]

```

---

<div class="post-metadata">

**Author:** ![hansmilton](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/hansmilton/32/8656_2.png) [@hansmilton](https://community.wolfram.com/u/hansmilton)\
**Post date:** [October 9, 2023, 6:16pm UTC](https://community.wolfram.com/t/applying-map-to-two-disconnected-levels/22942/3 "2023-10-09T18:16:39Z")

</div>

Using `Apply` for level 0:

```
mat = {{a1, b1}, {a2, b2}, {a3, b3}};
f @@ Map[f, mat, {2}]

(* f[{f[a1],f[b1]},{f[a2],f[b2]},{f[a3],f[b3]}] *)

```

---

<div class="post-metadata">

**Author:** ![eric3](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/eric3/32/12760_2.png) [@eric3](https://community.wolfram.com/u/eric3)\
**Post date:** [October 9, 2023, 6:45pm UTC](https://community.wolfram.com/t/applying-map-to-two-disconnected-levels/22942/4 "2023-10-09T18:45:00Z")

</div>

Your expected result is syntactically invalid, and so I’m actually not sure how you want to apply f. It seems like some combination of `Map`-ing and `Apply`ing. Also, I see `f` at three levels in your expected result, but you say you only want to apply it at two levels. Please correct your expected output or clarify your question.
