# Map a function at a given level of a tree

**URL:** <https://discourse.julialang.org/t/map-a-function-at-a-given-level-of-a-tree/27910>\
**Category:** General Usage\
**Created:** [August 23, 2019, 9:42pm UTC](https://discourse.julialang.org/t/map-a-function-at-a-given-level-of-a-tree/27910 "2019-08-23T21:42:02Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [August 23, 2019, 10:19pm UTC](https://discourse.julialang.org/t/map-a-function-at-a-given-level-of-a-tree/27910/2 "2019-08-23T22:19:46Z")

</div>

It can be done with a recursive definition like this:

> [@Idiomatic way to write element-wise combination of array of arrays?](https://discourse.julialang.org/t/idiomatic-way-to-write-element-wise-combination-of-array-of-arrays/18467/10):
>
> More generally, you can recursively define this broadcast up to any depth n like this julia\> function rebroadcast(f,n,args...) n\>1 ? rebroadcast(broadcast,n-1,(f,args...)) : broadcast(f, args...) end rebroadcast (generic function with 1 method) julia\> rebroadcast(div,1,[1],[2]) 1-element Array{Int64,1}: 0 julia\> rebroadcast(div,2,b,a) 2-element Array{Array{Int64,1},1}: [1, 0, 0] [0, 0, 0] julia\> rebroadcast(div,3,ab,aa) 2-element Array{Array{Array{Int64,1},1},1}: [[1, 1…

---

_[View the full topic](https://discourse.julialang.org/t/map-a-function-at-a-given-level-of-a-tree/27910)._
