# Is it possible to have an empty array of \>2 dims?

**URL:** <https://discourse.julialang.org/t/is-it-possible-to-have-an-empty-array-of-2-dims/42658>\
**Category:** General Usage\
**Tags:** question\
**Created:** [July 7, 2020, 6:24am UTC](https://discourse.julialang.org/t/is-it-possible-to-have-an-empty-array-of-2-dims/42658 "2020-07-07T06:24:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [July 7, 2020, 6:24am UTC](https://discourse.julialang.org/t/is-it-possible-to-have-an-empty-array-of-2-dims/42658/1 "2020-07-07T06:24:39Z")

</div>

The function `show_nd` in `arrayshow.jl` starts with [this](https://github.com/JuliaLang/julia/blob/63179af92cecbc575617648106e5b2f65f267c92/base/arrayshow.jl#L266-L270):

```julia
function show_nd(io::IO, a::AbstractArray, print_matrix::Function, label_slices::Bool)
    limit::Bool = get(io, :limit, false)
    if isempty(a)
        return
    end

```

This function is called only for arrays that have at least 3 dimensions. I was wondering if it’s possible to have an empty 3D array? I do not know how to construct one.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [July 7, 2020, 6:30am UTC](https://discourse.julialang.org/t/is-it-possible-to-have-an-empty-array-of-2-dims/42658/2 "2020-07-07T06:30:07Z")

</div>

Sure - `Array{Int, 3}(undef, 2,3,4)` is a valid call which returns an uninitialized three dimensional array of Ints with size `(2,3,4)`:

```julia
julia> Array{Int, 3}(undef, 2,3,4)
2×3×4 Array{Int64,3}:
[:, :, 1] =
 36 10 35
 12 24 16

[:, :, 2] =
 34 24 33
 22 28 31

[:, :, 3] =
 32 31 139790621598032
 34 35 139790621598032

[:, :, 4] =
 139790621598032 139790622082656 139790621598032
 139790621598032 139790622654688 139790552321744

```

This generalizes to N dimensions as well. There’s also `zeros`, initializing each element with `zero(T)`:

```julia
julia> zeros(Int, 2,3,4)
2×3×4 Array{Int64,3}:
[:, :, 1] =
 0 0 0
 0 0 0

[:, :, 2] =
 0 0 0
 0 0 0

[:, :, 3] =
 0 0 0
 0 0 0

[:, :, 4] =
 0 0 0
 0 0 0

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 7, 2020, 6:32am UTC](https://discourse.julialang.org/t/is-it-possible-to-have-an-empty-array-of-2-dims/42658/3 "2020-07-07T06:32:32Z")

</div>

I think here empty means “having 0 elements”. Eg

```julia
julia> a = Array{Int}(undef, 0, 0, 0)
0×0×0 Array{Int64,3}

julia> isempty(a)
true

```

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [July 7, 2020, 6:33am UTC](https://discourse.julialang.org/t/is-it-possible-to-have-an-empty-array-of-2-dims/42658/4 "2020-07-07T06:33:19Z")

</div>

Ah yes, that also makes sense - I was thinking empty as in no useful data 😃

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [July 7, 2020, 6:39am UTC](https://discourse.julialang.org/t/is-it-possible-to-have-an-empty-array-of-2-dims/42658/5 "2020-07-07T06:39:20Z")

</div>

Ah of course, thanks very much! This extends to `OffsetArray`s too where the axes ranges are empty.
