# Create multidimensional array spanned by unknown number of arrays

**URL:** https://discourse.julialang.org/t/create-multidimensional-array-spanned-by-unknown-number-of-arrays/70608
**Category:** General Usage
**Tags:** array, loops, arrays
**Created:** [October 29, 2021, 10:23am UTC](https://discourse.julialang.org/t/create-multidimensional-array-spanned-by-unknown-number-of-arrays/70608 "2021-10-29T10:23:19Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)
#### Post date: [October 29, 2021, 10:23am UTC](https://discourse.julialang.org/t/create-multidimensional-array-spanned-by-unknown-number-of-arrays/70608/1 "2021-10-29T10:23:19Z")

</div>

I have an (unknown) number of arrays, stored in an array:

```julia
arrays = [[1,2,3],[1,2,3,4],[1,2,3,4,5]] # In this case three

```

I want to create a multidimensional array, with one dimension for each array (so I don’t know the dimension). In each element of my new array, I want to have some element that is a function of the corresponding elements in the array:

```julia
function my_func(input)
    return sum(input)
end

```

In the case when I know the number of input arrays I can do this easily, e.g.

```julia
array_3d = [my_func([e1,e2,e3]) for e1 in arrays[1], e2 in arrays[2], e3 in arrays[3]]

```

but If I don’t know the number of arrays in my array, I don’t know how to do this.

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [October 29, 2021, 12:02pm UTC](https://discourse.julialang.org/t/create-multidimensional-array-spanned-by-unknown-number-of-arrays/70608/2 "2021-10-29T12:02:57Z")

</div>

Check for a [possible solution in this post](https://discourse.julialang.org/t/too-many-levels-of-nested-for-loops/56335/4).

---

<div class="post-metadata">

### Author: ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)
#### Post date: [October 29, 2021, 1:02pm UTC](https://discourse.julialang.org/t/create-multidimensional-array-spanned-by-unknown-number-of-arrays/70608/3 "2021-10-29T13:02:23Z")

</div>

Thanks. The last reply, suggesting:

```julia
N = 4
s = 0
for i in Iterators.product(fill(1:4, N)...)
    s += sum(i)
end

```

does work to loop through the arrays, and to do some function on them. However, it does not tell me how to save the function evaluations to an array. I could predeclare the array, but then it wouldn’t work if I didn’t know the dimensions.
