# Why does \[1; 2; 3\] creates an Array of dimension 1 instead of 3x1 Array of dimnesion 2

**URL:** <https://discourse.julialang.org/t/why-does-1-2-3-creates-an-array-of-dimension-1-instead-of-3x1-array-of-dimnesion-2/11233>\
**Category:** General Usage\
**Tags:** array\
**Created:** [May 29, 2018, 1:35pm UTC](https://discourse.julialang.org/t/why-does-1-2-3-creates-an-array-of-dimension-1-instead-of-3x1-array-of-dimnesion-2/11233 "2018-05-29T13:35:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![stakaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stakaz/32/4740_2.png) [@stakaz](https://discourse.julialang.org/u/stakaz)\
**Post date:** [May 29, 2018, 1:35pm UTC](https://discourse.julialang.org/t/why-does-1-2-3-creates-an-array-of-dimension-1-instead-of-3x1-array-of-dimnesion-2/11233/1 "2018-05-29T13:35:08Z")

</div>

Hello, following the docs `,` is a separator while `space` is a horizontal concatination and `;` is vertical one. Now, to have a consistant behavior, why not do it the following:

```julia
julia> [1, 2, 3]
3-element Array{Int64,1}:
 1
 2
 3

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

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

```

instead of the current behavior:

```julia
julia> [1, 2, 3]
3-element Array{Int64,1}:
 1
 2
 3

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

julia> [1; 2; 3]
3-element Array{Int64,1}:
 1
 2
 3

```

Because i case of [1 2; 3 4; 5 6] it **will** create a 3x2 Array anyway.

---

<div class="post-metadata">

**Author:** ![samtkaplan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/samtkaplan/32/2000_2.png) [@samtkaplan](https://discourse.julialang.org/u/samtkaplan)\
**Post date:** [May 29, 2018, 2:07pm UTC](https://discourse.julialang.org/t/why-does-1-2-3-creates-an-array-of-dimension-1-instead-of-3x1-array-of-dimnesion-2/11233/2 "2018-05-29T14:07:39Z")

</div>

I’m not sure I know the definitive answer to your question, but the semi-colon has another utility when constructing arrays. For example, consider the following two arrays, `x` and `y`:

```julia
x = [1,[2,3]]
y = [1;[2,3]]

```

`x` is a two element array with its first element being `1` and its second element being `[2,3]`. On the other hand, `y` is a three element array `[1,2,3]`.

For another example you could try:

```julia
z = [1:3;4:6]

```

vs

```julia
z = [1:3,4:6]

```

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [May 29, 2018, 2:19pm UTC](https://discourse.julialang.org/t/why-does-1-2-3-creates-an-array-of-dimension-1-instead-of-3x1-array-of-dimnesion-2/11233/3 "2018-05-29T14:19:28Z")

</div>

I agree that this is confusing, and it’s something I was confused by as well. The best explanation I have is that `;` is actually the vertical concatenation operator. So `[1; [2, 3]]` is equivalent to `vcat(1, [2, 3])` which is how we get `[1, 2, 3]`. By extension, `[1; 2; 3]` is also `vcat(1, 2, 3)` which is again `[1, 2, 3]` (that is, a Vector which is by convention a column vector). Vertical concatenation doesn’t create a new dimension if all of its inputs are 1- or 0-dimensional, so using `;` doesn’t give you a 2-dimensional `3x1` matrix, even though you might expect it to.

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [May 29, 2018, 2:36pm UTC](https://discourse.julialang.org/t/why-does-1-2-3-creates-an-array-of-dimension-1-instead-of-3x1-array-of-dimnesion-2/11233/4 "2018-05-29T14:36:43Z")

</div>

For reference the most succinct ways to produce an Nx1 matrix are

```julia
julia> [1 2 3]'
3×1 Array{Int64,2}:
 1
 2
 3

julia> v = [1, 2, 3]
3-element Array{Int64,1}:
 1
 2
 3

julia> hcat(v)
3×1 Array{Int64,2}:
 1
 2
 3

```

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [May 29, 2018, 2:40pm UTC](https://discourse.julialang.org/t/why-does-1-2-3-creates-an-array-of-dimension-1-instead-of-3x1-array-of-dimnesion-2/11233/5 "2018-05-29T14:40:00Z")

</div>

Just for reference:

> [@How to create a 2x1 Array?](https://discourse.julialang.org/t/how-to-create-a-2x1-array/8337):
>
> TL;DR, answer: to get a 2x1 Array/Matrix transpose a 1x2 matrix, for example: [2 4]' A more general solution that also works for complex numbers in Julia V0.7- would be transpose([2 4]) I wanted to test julia\> maximum([1 2; 3 4], 2) 2×1 Array{Int64,2}: 2 4 So I tried julia\> maximum([1 2; 3 4], 2) == [2;4] false I expected the value to be true, but the value is false because julia\> [2;4] 2-element Array{Int64,1}: 2 4 That is, a 2×1 Array{Int64,2} is not the same as a 2-element Arra…

> <https://github.com/JuliaLang/julia/issues/7128>
>
> Much gnashing of teeth derives from the overlap between syntax for array literal… construction and array concatenation in Julia – largely inherited from Matlab. Perhaps we should just use a different syntax for block matrix construction entirely. One thought would be this:
> 
> \`\`\` julia
> | a b
> c d |
> \`\`\`
> 
> This has the advantage of being pretty terse and lightweight. For example, the current idiom of expanding a range into an array is \`\[1:10\]\` which would become \`|1:10|\` while \`\[1:10\]\` would construct a one-element array of type \`UnitRange{Int}\`.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [May 29, 2018, 2:41pm UTC](https://discourse.julialang.org/t/why-does-1-2-3-creates-an-array-of-dimension-1-instead-of-3x1-array-of-dimnesion-2/11233/6 "2018-05-29T14:41:52Z")

</div>

> [@GunnarFarneback](#):
>
> ```julia
> julia> [1 2 3]' 
> 3×1 Array{Int64,2}: 
> 1 
> 2 
> 3
> 
> ```

this will not produce a matrix in Julia v0.7. Now that we [take matrix transpose seriously](https://github.com/JuliaLang/julia/issues/20978), it produces an `Adjoint`:

```julia
julia> [1, 2, 3]'
1×3 LinearAlgebra.Adjoint{Int64,Array{Int64,1}}:
 1 2 3

```

this in turn actually simplifies a lot of internal stuff, as `x' * y` no longer has to have a special expansion rule to turn it into a call to the cryptically-named `Ac_mul_b`.

Edit: oops, linked to the wrong “taking foo seriously” issue

---

<div class="post-metadata">

**Author:** ![stakaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stakaz/32/4740_2.png) [@stakaz](https://discourse.julialang.org/u/stakaz)\
**Post date:** [May 31, 2018, 7:34am UTC](https://discourse.julialang.org/t/why-does-1-2-3-creates-an-array-of-dimension-1-instead-of-3x1-array-of-dimnesion-2/11233/7 "2018-05-31T07:34:27Z")

</div>

Thanks for the explanations. Now I kind of understand the reasons 😉

---

<div class="post-metadata">

**Author:** ![Iagoba\_Apellaniz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iagoba_apellaniz/32/34406_2.png) [@Iagoba\_Apellaniz](https://discourse.julialang.org/u/Iagoba_Apellaniz)\
**Post date:** [May 31, 2018, 8:40am UTC](https://discourse.julialang.org/t/why-does-1-2-3-creates-an-array-of-dimension-1-instead-of-3x1-array-of-dimnesion-2/11233/8 "2018-05-31T08:40:32Z")

</div>

Anyway the `Adjoint` type will have dimension 2 and size Nx1, as expected for a matrix. Effectively, it is a matrix that runs faster 😅.
