# Tiny suggestion: REPL printout of 1-dim arrays as rows

**URL:** <https://discourse.julialang.org/t/tiny-suggestion-repl-printout-of-1-dim-arrays-as-rows/8012>\
**Category:** Internals & Design\
**Created:** [December 27, 2017, 2:42am UTC](https://discourse.julialang.org/t/tiny-suggestion-repl-printout-of-1-dim-arrays-as-rows/8012 "2017-12-27T02:42:45Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivo\_welch](https://avatars.discourse-cdn.com/v4/letter/i/d2c977/32.png) [@ivo\_welch](https://discourse.julialang.org/u/ivo_welch)\
**Post date:** [December 27, 2017, 2:42am UTC](https://discourse.julialang.org/t/tiny-suggestion-repl-printout-of-1-dim-arrays-as-rows/8012/1 "2017-12-27T02:42:45Z")

</div>

the REPL prints a nice display for a 1-dimensional arrays, but it takes a lot of rows. Instead of printing 1-D arrays in one column, the REPL could save some terminal line space by print a row, more like R:

\> 1:20+0.1  
[1] 1.1 2.1 3.1 4.1 5.1 6.1 7.1 8.1 9.1 10.1 11.1 12.1 13.1 14.1 15.1 16.1 17.1 18.1 19.1 20.1

as noted in the title, this is a minor nuisance.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [December 27, 2017, 3:06am UTC](https://discourse.julialang.org/t/tiny-suggestion-repl-printout-of-1-dim-arrays-as-rows/8012/2 "2017-12-27T03:06:37Z")

</div>

If you want, you could transpose the vector giving you a RowVector which prints the way you prefer it:

```julia
julia> ((1:20) .+ 0.1)'
1×20 RowVector{Float64,Array{Float64,1}}:
 1.1 2.1 3.1 4.1 5.1 6.1 7.1 8.1 … 14.1 15.1 16.1 17.1 18.1 19.1 20.1

```

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [December 27, 2017, 7:04am UTC](https://discourse.julialang.org/t/tiny-suggestion-repl-printout-of-1-dim-arrays-as-rows/8012/3 "2017-12-27T07:04:21Z")

</div>

I find the current format useful because I can immediately see the dimensionality of an array. A column vector is printed as a column vector and row one as a row. It makes most sense to me.

Not to mention that there are mechanisms in place to “save” as much terminal-estate as possible, so it’s a win-win.

---

<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:** [December 27, 2017, 7:35am UTC](https://discourse.julialang.org/t/tiny-suggestion-repl-printout-of-1-dim-arrays-as-rows/8012/4 "2017-12-27T07:35:32Z")

</div>

> [@ivo\_welch](#):
>
> the REPL could save some terminal line space by print a row

Try `showcompact`.

---

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [December 27, 2017, 5:14pm UTC](https://discourse.julialang.org/t/tiny-suggestion-repl-printout-of-1-dim-arrays-as-rows/8012/5 "2017-12-27T17:14:59Z")

</div>

yes, one can indeed change specific expression. but I think it is the kind of thing that would nicely make for a REPL display option. some may prefer one, some another. (thanks for having listened.  
it was a tiny suggestion, anyway.) if an option is set, it could

julia\> collect(1:20)  
20-element Array{Int64,1}: T: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

julia\> (collect(1:20))’  
1×20 Transpose{Int64,Array{Int64,1}}:  
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

I am learning julia, so I am puzzled by the type displays. 20×1 and 1×20 should be column and row vectors. I am guessing that an Array is always completely identical to a column vector, by default, and it always omit “×1”\* printing at the end. The word “element” is nice. But what is the `Transpose` in the second type display, though? Why not just 1×20 Array{Int64,1}? I don’t want to keep the developers’ time on this, though. This belongs into “usage” for beginners.

---

<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:** [December 27, 2017, 5:34pm UTC](https://discourse.julialang.org/t/tiny-suggestion-repl-printout-of-1-dim-arrays-as-rows/8012/6 "2017-12-27T17:34:52Z")

</div>

> I am guessing that an Array is always completely identical to a column vector, by default, and it always omit “×1”\* printing at the end

That’s a reasonable guess, but it’s not true in Julia (it’s a common misconception, especially for people coming from Matlab). A vector in Julia is truly a 1-dimensional object, and although an N-element vector and an Nx1 matrix may have the same number of elements, they are actually different types and can behave differently:

```julia
julia> myvector = fill(0.0, 2) # 2-element vector
2-element Array{Float64,1}:
 0.0
 0.0

julia> size(myvector) # returns a 1-element tuple because there is only one dimension
(2,)

julia> mymatrix = fill(0.0, 2, 1) # 2x1 matrix
2×1 Array{Float64,2}:
 0.0
 0.0

julia> size(mymatrix) # returns a 2-element tuple
(2, 1)

julia> typeof(myvector) # Array{Float64, 1}, in which 1 is the number of dimensions
Array{Float64,1}

julia> typeof(mymatrix) # Array{Float64, 2}, because it has 2 dimensions
Array{Float64,2}

julia> myvector == mymatrix # a matrix and a vector are not the same thing
false

```

---

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [December 27, 2017, 5:49pm UTC](https://discourse.julialang.org/t/tiny-suggestion-repl-printout-of-1-dim-arrays-as-rows/8012/7 "2017-12-27T17:49:26Z")

</div>

thank you, robin. but then, another confused beginner question. if an array is direction-less, why should it be printed as a column vector?? now there is neither a logical reason nor good space use of the terminal. (and what is a Transpose type then??)

---

<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:** [December 27, 2017, 6:11pm UTC](https://discourse.julialang.org/t/tiny-suggestion-repl-printout-of-1-dim-arrays-as-rows/8012/8 "2017-12-27T18:11:01Z")

</div>

If you want all the gory details, you can read the discussion at [https://github.com/JuliaLang/julia/issues/4774](https://github.com/JuliaLang/julia/issues/4774) or watch this talk from JuliaCon: [JuliaCon 2017 | Taking Vector Transposes Seriously | Jiahao Chen - YouTube](https://www.youtube.com/watch?v=C2RO34b_oPM)

But if you just want a simple justification, then consider that vectors behave like columns under matrix multiplication:

```julia
julia> M = zeros(2, 2)
2×2 Array{Float64,2}:
 0.0 0.0
 0.0 0.0

julia> v = zeros(2)
2-element Array{Float64,1}:
 0.0
 0.0

julia> M * v
2-element Array{Float64,1}:
 0.0
 0.0

julia> M * v'
ERROR: DimensionMismatch("A has dimensions (2,2) but B has dimensions (1,2)")

```

---

<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 27, 2017, 9:08pm UTC](https://discourse.julialang.org/t/tiny-suggestion-repl-printout-of-1-dim-arrays-as-rows/8012/9 "2017-12-27T21:08:48Z")

</div>

We used to do this. As a result, there was a lot of confusion about the fact that vectors printed as rows but behave like columns. We changed the printing of vectors to be vertical and the confusion went away, and it became immediately obvious to people that vectors should behave like columns, not rows.

I really _wish_ that vectors were identified with rows instead of columns, since that would make many things much more convenient, but that ship has sailed long ago – linear algebra is firmly column-oriented. Given that, we can either live with this and match every linear algebra text ever or change it and start our own dialect of mathematics.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [December 27, 2017, 10:27pm UTC](https://discourse.julialang.org/t/tiny-suggestion-repl-printout-of-1-dim-arrays-as-rows/8012/10 "2017-12-27T22:27:38Z")

</div>

Some (many? old?) maths books print vectors as e.g.

```julia
(3, 4, 5)ᵀ

```

with the transpose symbol, to both save space and be mathematically “correct” when thinking of column vectors.

---

<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:** [December 27, 2017, 11:12pm UTC](https://discourse.julialang.org/t/tiny-suggestion-repl-printout-of-1-dim-arrays-as-rows/8012/11 "2017-12-27T23:12:50Z")

</div>

> [@dpsanders](#):
>
> Some (many? old?) maths books print vectors as e.g. `(3, 4, 5)ᵀ`

You are probably thinking of `(3 4 5)ᵀ` or `[3 4 5]ᵀ`, since row vectors are usually not comma-delimited.

IIRC, Strang’s book prints row vectors as `[3 4 5]` and prints column vectors inline as `(3,4,5)`, but I find that students easily get confused by this.

---

<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:** [December 27, 2017, 11:14pm UTC](https://discourse.julialang.org/t/tiny-suggestion-repl-printout-of-1-dim-arrays-as-rows/8012/12 "2017-12-27T23:14:28Z")

</div>

I usually use `print(A)` when I want to see a vector compactly.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [December 27, 2017, 11:31pm UTC](https://discourse.julialang.org/t/tiny-suggestion-repl-printout-of-1-dim-arrays-as-rows/8012/13 "2017-12-27T23:31:44Z")

</div>

Wikipedia lists both (/ various) notations:

> **[Row and column vectors](https://en.wikipedia.org/wiki/Row_and_column_vectors)**
>
> In linear algebra, a column vector with 
>   
>     
>       
> m
>       
>     
> {\\displaystyle m}
>   
> elements is an 
>   
>     
>       
> m
> ×
> 1
>       
>     
> {\\displaystyle m\\times 1}
>   
> matrix consisting of a single column of 
>   
>     
>       
> m
>       
>     
> {\\displaystyle m}
>   
> entries, for example,
> Similarly, a row vector is a 
>   
>     
>       
> 1
> ×
> n
>       
>     
> {\\displaystyle 1\\times n}
>   
> matrix for some 
>   
>     
>       
> n
> ...
