# Why the 1x1 matrix \[2\] is printed \[2;;\]?

**URL:** <https://discourse.julialang.org/t/why-the-1x1-matrix-2-is-printed-2/91486>\
**Category:** General Usage\
**Tags:** matrices\
**Created:** [December 9, 2022, 6:06pm UTC](https://discourse.julialang.org/t/why-the-1x1-matrix-2-is-printed-2/91486 "2022-12-09T18:06:35Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/_stla/32/35613_2.png) [@\_stla](https://discourse.julialang.org/u/_stla)\
**Post date:** [December 9, 2022, 6:06pm UTC](https://discourse.julialang.org/t/why-the-1x1-matrix-2-is-printed-2/91486/1 "2022-12-09T18:06:35Z")

</div>

Hello,

```julia
julia> x = repeat([2], 1, 1)
1x1 Matrix{Int64}:
 2

julia> print(x)
[2;;]

```

Why `[2;;]`?

---

<div class="post-metadata">

**Author:** ![mikmoore](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikmoore/32/31109_2.png) [@mikmoore](https://discourse.julialang.org/u/mikmoore)\
**Post date:** [December 9, 2022, 6:14pm UTC](https://discourse.julialang.org/t/why-the-1x1-matrix-2-is-printed-2/91486/2 "2022-12-09T18:14:33Z")

</div>

```julia-repl
julia> typeof([2])
Vector{Int64} (alias for Array{Int64, 1})

julia> typeof([2;;])
Matrix{Int64} (alias for Array{Int64, 2})

```

If you were to write it as `[2]`, it would be a `Vector` of size `(1,)`. It’s necessary to write it was `[2;;]` to form a `Matrix` with size `(1,1)`. It’s printed this way so that it can be re-parsed accurately.

It seems you might have preferred `[2]` in this case. Unfortunately, I don’t have the answer for how to achieve that except by checking for this special case explicitly.

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [December 9, 2022, 6:17pm UTC](https://discourse.julialang.org/t/why-the-1x1-matrix-2-is-printed-2/91486/3 "2022-12-09T18:17:29Z")

</div>

Also for more context, Julia uses the `;` to separate dimension in multidimensional arrays with more semicolons indicating higher dimensions. Since a `Matrix` is just a 2-d `Array`, there are two semicolons, one for each dimension.

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [December 9, 2022, 6:29pm UTC](https://discourse.julialang.org/t/why-the-1x1-matrix-2-is-printed-2/91486/4 "2022-12-09T18:29:24Z")

</div>

Another way to say the same thing:

```julia
julia> size([1; 2; 3]) 
(3,)
julia> size([1;; 2;; 3])
(1, 3)
julia> size([1;])
(1,)
julia> size([1;;])
(1, 1)
```

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [December 9, 2022, 7:02pm UTC](https://discourse.julialang.org/t/why-the-1x1-matrix-2-is-printed-2/91486/5 "2022-12-09T19:02:51Z")

</div>

While not absolute, Julia does tend to support [homoiconicity](https://en.wiktionary.org/wiki/homoiconicity#:~:text=Noun,type%20of%20the%20language%20itself). The representation of the data structure is also how to type the data structure in the language.

There are a few different ways to “print” data structures in Julia.

```julia
julia> x = repeat([2], 1, 1)
1×1 Matrix{Int64}:
 2

julia> print(x)
[2;;]
julia> display(x)
1×1 Matrix{Int64}:
 2

julia> show(x)
[2;;]

julia> show(stdout, MIME"text/plain"(), x)
1×1 Matrix{Int64}:
 2

julia> [2;;] == x
true

```

If you are coming from MATLAB, this may be confusing since MATLAB drops singleton dimensions and also considers everything to be a matrix by default. Julia does not do this.

---

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [December 9, 2022, 7:55pm UTC](https://discourse.julialang.org/t/why-the-1x1-matrix-2-is-printed-2/91486/6 "2022-12-09T19:55:39Z")

</div>

```julia
julia> [1;]
1-element Vector{Int64}:
 1

julia> [1;;]
1×1 Matrix{Int64}:
 1

julia> [1;;;]
1×1×1 Array{Int64, 3}:
[:, :, 1] =
 1

julia> [1;;;;]
1×1×1×1 Array{Int64, 4}:
[:, :, 1, 1] =
 1

julia> [1;;;;;]
1×1×1×1×1 Array{Int64, 5}:
[:, :, 1, 1, 1] =
 1

julia> [1;;;;;;]
1×1×1×1×1×1 Array{Int64, 6}:
[:, :, 1, 1, 1, 1] =
 1

julia> [1;;;;;;;]
1×1×1×1×1×1×1 Array{Int64, 7}:
[:, :, 1, 1, 1, 1, 1] =
 1

julia> [1;;;;;;;;]
1×1×1×1×1×1×1×1 Array{Int64, 8}:
[:, :, 1, 1, 1, 1, 1, 1] =
 1

julia> [1;;;;;;;;;]
1×1×1×1×1×1×1×1×1 Array{Int64, 9}:
[:, :, 1, 1, 1, 1, 1, 1, 1] =
 1

julia> [1;;;;;;;;;;]
1×1×1×1×1×1×1×1×1×1 Array{Int64, 10}:
[:, :, 1, 1, 1, 1, 1, 1, 1, 1] =
 1

```

While it is unlikely you will live long enough to declare a 10-dimensional array using this syntax, it’s there just in case.

To understand why this syntax is here:

```julia
julia> [1; 2;; 3; 4]
2×2 Matrix{Int64}:
 1 3
 2 4

julia> [1 3; 2 4]
2×2 Matrix{Int64}:
 1 3
 2 4

julia> [1 3; 2 4;;; 5 7; 6 8]
2×2×2 Array{Int64, 3}:
[:, :, 1] =
 1 3
 2 4

[:, :, 2] =
 5 7
 6 8

julia> [1; 2;; 3; 4;;; 5; 6;; 7; 8]
2×2×2 Array{Int64, 3}:
[:, :, 1] =
 1 3
 2 4

[:, :, 2] =
 5 7
 6 8

julia> ([1; 2;; 3; 4;;; 5; 6;; 7; 8]...,)
(1, 2, 3, 4, 5, 6, 7, 8)

```

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [December 9, 2022, 8:48pm UTC](https://discourse.julialang.org/t/why-the-1x1-matrix-2-is-printed-2/91486/7 "2022-12-09T20:48:15Z")

</div>

> [@gustaphe](#):
>
> ```julia
> julia> size([1;; 2;; 3])
> (1, 2)
> 
> ```

What?

---

<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:** [December 9, 2022, 9:29pm UTC](https://discourse.julialang.org/t/why-the-1x1-matrix-2-is-printed-2/91486/8 "2022-12-09T21:29:56Z")

</div>

Must have been hand-edited output. Actual size is `(1, 3)`.

---

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [December 9, 2022, 11:39pm UTC](https://discourse.julialang.org/t/why-the-1x1-matrix-2-is-printed-2/91486/9 "2022-12-09T23:39:52Z")

</div>

I wanted to confirm but I’m AFK, so I tried [this online REPL](https://julialang.org/learning/tryjulia/) and got an unexpected result 😅

 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/5/654796a8ed6d5d9def27a0b419f7edebf6d65241.jpeg)

---

<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:** [December 10, 2022, 5:31am UTC](https://discourse.julialang.org/t/why-the-1x1-matrix-2-is-printed-2/91486/10 "2022-12-10T05:31:52Z")

</div>

That’s an older Julia version.

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [December 10, 2022, 9:51am UTC](https://discourse.julialang.org/t/why-the-1x1-matrix-2-is-printed-2/91486/11 "2022-12-10T09:51:57Z")

</div>

Yep, this is why I don’t normally code on my phone.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [December 10, 2022, 8:23pm UTC](https://discourse.julialang.org/t/why-the-1x1-matrix-2-is-printed-2/91486/12 "2022-12-10T20:23:46Z")

</div>

Why is that? I run Julia on my phone all the time via [termux](https://termux.dev/en/). Because of this, I can run the latest version of Julia on my phone without relying on repl.it to update Julia to the latest version in order to take advantage of the latest features.

In this case, I can run Julia 1.8.3 on my phone to get the correct result.

```julia
julia> x = [1;; 2;; 3]
1×3 Matrix{Int64}:
 1 2 3

julia> size(x)
(1, 3)

```

 ![Screenshot_20221210_152221_Termux](https://global.discourse-cdn.com/julialang/original/3X/d/1/d133b78cb6961caf93bbca2b747da460761b80f5.jpeg)  
 ![Screenshot_20221210_152157_Termux](https://global.discourse-cdn.com/julialang/original/3X/7/c/7c0fd18aa43ff2824fa258c64c0393cbd299a1a3.jpeg)

edit: This is on-topic because this original poster’s behavior depends on running a recent version of Julia. Other posters have commented they could not reproduce the behavior on their phone since they can only access older versions of Julia online. I am demonstrating how to run recent versions of Julia on a phone and provided a mechanism to do so.

---

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [December 10, 2022, 8:49pm UTC](https://discourse.julialang.org/t/why-the-1x1-matrix-2-is-printed-2/91486/13 "2022-12-10T20:49:30Z")

</div>

If only I could run Julia on my iPad 😅
