# Creating Column Matrix with Array Literals

**URL:** <https://discourse.julialang.org/t/creating-column-matrix-with-array-literals/53742>\
**Category:** General Usage\
**Tags:** array\
**Created:** [January 21, 2021, 7:54pm UTC](https://discourse.julialang.org/t/creating-column-matrix-with-array-literals/53742 "2021-01-21T19:54:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dariush-bahrami](https://avatars.discourse-cdn.com/v4/letter/d/f1d935/32.png) [@dariush-bahrami](https://discourse.julialang.org/u/dariush-bahrami)\
**Post date:** [January 21, 2021, 7:54pm UTC](https://discourse.julialang.org/t/creating-column-matrix-with-array-literals/53742/1 "2021-01-21T19:54:15Z")

</div>

Hi, How we can create a column matrix (i.e. nx1) with array literals? I am aware of other ways for achieving this such as using initializer functions such as “zeros” and “ones”. but how we can do this with array literals? I expect the following snippet create a column matrix:

```julia
A = [1; 2]

```

and also following snippet:

```julia
A = [1
     2]

```

but both of this will create a 1 dimensional array as “2-element Array{Int64,1}”.  
in [Documetation](https://docs.julialang.org/en/v1/manual/arrays/#man-array-literals) explicitly states:

> Concatenation  
> If the arguments inside the square brackets are separated by semicolons ( `;` ) or newlines \>instead of commas, then their contents are _vertically concatenated_ together instead of the \>arguments being used as elements themselves.

I think this is a little inconsistency in Julia syntax.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 21, 2021, 7:59pm UTC](https://discourse.julialang.org/t/creating-column-matrix-with-array-literals/53742/2 "2021-01-21T19:59:54Z")

</div>

> [@dariush-bahrami](#):
>
> I think this a little inconsistency in Julia syntax.

No, because 1d arrays are treated as column vectors in all of the Julia linear-algebra routines. (Because of this, it’s not clear why you need to create a 1-column matrix instead of a 1d array?)

You could use `reshape([1,2],2,1)`.

(It might also make sense to have a constructor `Matrix(x::Vector) = reshape(x, length(x), 1)`; currently there is no such constructor defined in Base.)

See also [this discussion](https://discourse.julialang.org/t/vector-vs-column-vector/34699) and [issue #17084](https://github.com/JuliaLang/julia/issues/17084).

---

<div class="post-metadata">

**Author:** ![dariush-bahrami](https://avatars.discourse-cdn.com/v4/letter/d/f1d935/32.png) [@dariush-bahrami](https://discourse.julialang.org/u/dariush-bahrami)\
**Post date:** [January 21, 2021, 8:07pm UTC](https://discourse.julialang.org/t/creating-column-matrix-with-array-literals/53742/3 "2021-01-21T20:07:15Z")

</div>

Thank you for your respond. my point is if semicolon or newline concatenate vertically why it does not work in this case?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 21, 2021, 8:08pm UTC](https://discourse.julialang.org/t/creating-column-matrix-with-array-literals/53742/4 "2021-01-21T20:08:34Z")

</div>

> [@dariush-bahrami](#):
>
> my point is if semicolon or newline concatenate vertically why it does not work in this case?

Because it _is_ doing “vertical” concatentation ([`vcat`](https://docs.julialang.org/en/v1/base/arrays/#Base.vcat)) — from Julia’s perspective, a 1d array is “vertical”, and more generally the **first dimension** of any array (of _any dimensionality_) is defined to be “vertical”. For the same reason:

```julia
julia> [[3,4]; [5,6]]
4-element Array{Int64,1}:
 3
 4
 5
 6

julia> size([rand(3,4,5); rand(17,4,5)])
(20, 4, 5)

```

---

<div class="post-metadata">

**Author:** ![dariush-bahrami](https://avatars.discourse-cdn.com/v4/letter/d/f1d935/32.png) [@dariush-bahrami](https://discourse.julialang.org/u/dariush-bahrami)\
**Post date:** [January 21, 2021, 8:46pm UTC](https://discourse.julialang.org/t/creating-column-matrix-with-array-literals/53742/5 "2021-01-21T20:46:35Z")

</div>

Thank you. your explanation helped.
