Idiomatic way to write element-wise combination of array of arrays?

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, 1], [1, 1, 1]]
 [[1, 0, 0], [0, 0, 0]]
1 Like