# 1-Column matrix vs. Vector

**URL:** <https://discourse.julialang.org/t/1-column-matrix-vs-vector/71440>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [November 13, 2021, 10:28pm UTC](https://discourse.julialang.org/t/1-column-matrix-vs-vector/71440 "2021-11-13T22:28:39Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [November 14, 2021, 12:04am UTC](https://discourse.julialang.org/t/1-column-matrix-vs-vector/71440/10 "2021-11-14T00:04:35Z")

</div>

> [@goerch](#):
>
> So compromises have to be made, probably.

Yeah… I tried to follow some GitHub issues on the original design of these, but they are pretty technical. What’s clear is that everyone involved had clear knowledge on what Matlab does, and they agreed that having that distinction is a good thing. I’ve seen also a C. Elrod post demonstrating that some compiler optimizations are easier with vectors (vs. Matrices that happen to have one column), particularly for simd.

In Matlab even a scalar is a Matrix with one row and one column. In Julia this would be very bad, since scalars are immutable types, and matrices are heap allocated. Probably something like that, yet more subtle, is related to the choice of having true vectors.

Some sources: [(Row)Vector equality with Matrices · Issue #21998 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/21998)

> [@1d arrays vs 1-column matrices](https://discourse.julialang.org/t/1d-arrays-vs-1-column-matrices/46101/8):
>
> The compiler has more information about a vector than a matrix: it knows the second dimension is 1. This can yield better performance in cases such as: julia\> x = rand(128); X = reshape(x, (length(x),1)); julia\> typeof.((x, X)) (Array{Float64,1}, Array{Float64,2}) julia\> A = rand(32,128); B = similar(A); julia\> @benchmark @. $B = $A + $x' BenchmarkTools.Trial: memory estimate: 0 bytes allocs estimate: 0 -------------- minimum time: 773.423 ns (0.00% GC) median time: 784…

---

_[View the full topic](https://discourse.julialang.org/t/1-column-matrix-vs-vector/71440)._
