# Irregularity in array definition API

**URL:** <https://discourse.julialang.org/t/irregularity-in-array-definition-api/43573>\
**Category:** General Usage\
**Created:** [July 23, 2020, 5:56pm UTC](https://discourse.julialang.org/t/irregularity-in-array-definition-api/43573 "2020-07-23T17:56:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pauljurczak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauljurczak/32/921_2.png) [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)\
**Post date:** [July 23, 2020, 5:56pm UTC](https://discourse.julialang.org/t/irregularity-in-array-definition-api/43573/1 "2020-07-23T17:56:35Z")

</div>

I can define an uninitialized array this way:

```julia
a = Array{Int32, 2}(undef, 10, 10)

```

but I can’t define an initialized array the same way:

```julia
a = Array{Int32, 2}(42, 10, 10)

```

I have to use this form instead:

```julia
a = fill(Int32(42), 10, 10)

```

Is there a deeper reason for this? The first form is also used to initialize arrays with ‘nothing’ or ‘missing’, so it overlaps initialized and uninitialized construction category.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [July 23, 2020, 6:44pm UTC](https://discourse.julialang.org/t/irregularity-in-array-definition-api/43573/2 "2020-07-23T18:44:30Z")

</div>

What value should the array be initialized with when you do `Array{Int32, 2}(42, 10, 10)`? Do you want the first value to be used to fill the array? Or should `42` be interpreted as a dimension of the resulting array?

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [July 23, 2020, 7:08pm UTC](https://discourse.julialang.org/t/irregularity-in-array-definition-api/43573/3 "2020-07-23T19:08:28Z")

</div>

`Array{Int,2}(undef, N1, N2)` is like `Array{Int,2}(undef, (N1,N2))`.  
`Array{Int,2}(42, N1, N2)` could be like `Array{Int,2}(42, (N1,N2))` which could be as `fill(42, (N1,N2))`.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [July 23, 2020, 7:09pm UTC](https://discourse.julialang.org/t/irregularity-in-array-definition-api/43573/4 "2020-07-23T19:09:58Z")

</div>

Array constructors in general are in need of some love.

---

<div class="post-metadata">

**Author:** ![pauljurczak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauljurczak/32/921_2.png) [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)\
**Post date:** [July 23, 2020, 7:18pm UTC](https://discourse.julialang.org/t/irregularity-in-array-definition-api/43573/5 "2020-07-23T19:18:03Z")

</div>

> [@StefanKarpinski](#):
>
> What value should the array be initialized with when you do `Array{Int32, 2}(42, 10, 10)` ?

I see the problem with this option now. As @JeffreySarnoff noted, `Array{Int32, 2}(42, (10, 10))` could be the way out.

**EDIT**

BTW, `fill(42, 10, 10)` doesn’t make it obvious which arguments are dimensions and which is the value to fill with.
