# How to display the elements of 1D array in one line?

**URL:** <https://discourse.julialang.org/t/how-to-display-the-elements-of-1d-array-in-one-line/65925>\
**Category:** General Usage\
**Created:** [August 6, 2021, 4:05am UTC](https://discourse.julialang.org/t/how-to-display-the-elements-of-1d-array-in-one-line/65925 "2021-08-06T04:05:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![CRquantum](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/crquantum/32/27824_2.png) [@CRquantum](https://discourse.julialang.org/u/CRquantum)\
**Post date:** [August 6, 2021, 4:05am UTC](https://discourse.julialang.org/t/how-to-display-the-elements-of-1d-array-in-one-line/65925/1 "2021-08-06T04:05:52Z")

</div>

I have an array a,

```
a=Array{Float64,1}()
for i in 1:10
    push!(a,i*10.0)
end
display(a)

```

However, println or display, they all show the elements of the array vertically, like below

10-element Array{Float64,1}:  
10.0  
20.0  
30.0  
40.0  
50.0  
60.0  
70.0  
80.0  
90.0  
100.0

1. However, is there a simply command so that it can just show all the elements in one line like

and better also can specify the distance between the elements, like the 10(g15.7,1x) in Fortran.

1. Futhermore, if I have another array b which can be any value but still 10 elements. Now I want to display a and b in two lines, but they need to be displayed aligned, like,  
println( script for display a)  
println ( script for display b )

is there a way to achieve this?

Thanks in advance!

* * *

Edit:

In fact I wanted to display things like below,

```
----- Iteration = 47 -> Log Likelihood = -5.158964
Sigma = 0.10265 +- 0.00199
Mixture Label : 1 | 2 |
Weight = 0.20000 | 0.80000 |
Mu_k = 0.63695 +- 0.00333 | 0.30996 +- 0.00484 |
Sig Mu_k = 0.03692 +- 0.00201 | 0.05363 +- 0.00336 |
Mu_V = 20.01389 +- 0.12476 | 20.01389 +- 0.12476 |
Sig Mu_V = 1.95679 +- 0.08312 | 1.95679 +- 0.08312 |
Mu_k MC acc rate = 2.880% | 9.941% |
Mu_V MC acc rate = 5.731% | 5.731% |
-----------------------------------------------------------------------------

```

it is gaussian mixture model, k=1,2.  
For each k, I want to show all the results. I want to show them horizontally than vertically.  
Because for each k if I need 10 lines, for k=10, if I show them vertically it will take 500 lines which is very inconvenient. But if I show them horizontally, it will only take 10 lines, and it is wide, but is conveneint.  
The thing is currently done using Fortran’s format IO, I am still trying to get used to Julia.

---

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [August 6, 2021, 4:07am UTC](https://discourse.julialang.org/t/how-to-display-the-elements-of-1d-array-in-one-line/65925/2 "2021-08-06T04:07:48Z")

</div>

```julia

julia> join(1:10, " ")
"1 2 3 4 5 6 7 8 9 10"
```

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [August 6, 2021, 5:42am UTC](https://discourse.julialang.org/t/how-to-display-the-elements-of-1d-array-in-one-line/65925/3 "2021-08-06T05:42:02Z")

</div>

Julia vectors are columns, so it makes sense to print them like columns. If you want to have “row”, you can use a single row matrix `Matrix{Float64}(undef, 1,10)`. You won’t be able to push to it (since single element pushing doesn’t make sense for a matrix), so you’ll have to declare it with `undef` and fill it by indexing.

> [@CRquantum](#):
>
> specify the distance between the elements, like the 10(g15.7,1x) in Fortran.

Not 100% sure what you mean, but are you maybe looking for `range(start=1, step=15.7, length=10)`?

> [@CRquantum](#):
>
> Futhermore, if I have another array b which can be any value but still 10 elements. Now I want to display a and b in two lines, but they need to be displayed aligned, like,

Check out the [Printf stdlib](https://docs.julialang.org/en/v1/stdlib/Printf/). There’s no function that does what you want out of the box, but it should be fairly easy to achieve what you want with that.

---

<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:** [August 6, 2021, 6:40am UTC](https://discourse.julialang.org/t/how-to-display-the-elements-of-1d-array-in-one-line/65925/4 "2021-08-06T06:40:19Z")

</div>

If you are just interested in showing this in the REPL for your own use, you can just transpose the vector, and let Julia display it for you:

```julia
jl> a = collect(10.0:10:100.0); # no need for that awkward loop

jl> a'
1×10 adjoint(::Vector{Float64}) with eltype Float64:
 10.0 20.0 30.0 40.0 50.0 60.0 70.0 80.0 90.0 100.0

```

If you don’t want the header:

```julia
jl> show(a')
[10.0 20.0 30.0 40.0 50.0 60.0 70.0 80.0 90.0 100.0]

```

If you also have a vector `b`:

```julia
jl> b = rand(10) .* 1000;

jl> [a'; b']
2×10 Matrix{Float64}:
  10.0 20.0 30.0 40.0 50.0 60.0 70.0 80.0 90.0 100.0
 443.6 144.745 63.4774 751.4 2.70519 353.378 13.6564 737.546 644.369 609.264

```

`show` does not work quite as well here:

```julia
jl> show([a'; b'])
[10.0 20.0 30.0 40.0 50.0 60.0 70.0 80.0 90.0 100.0; 443.600262923888 144.74517496650608 63.4773542697542 751.4002143975607 2.7051915255487113 353.3781191303855 13.65636167386497 737.5456627385262 644.3692182949352 609.2643705463589]

```

---

<div class="post-metadata">

**Author:** ![CRquantum](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/crquantum/32/27824_2.png) [@CRquantum](https://discourse.julialang.org/u/CRquantum)\
**Post date:** [August 6, 2021, 8:06am UTC](https://discourse.julialang.org/t/how-to-display-the-elements-of-1d-array-in-one-line/65925/5 "2021-08-06T08:06:25Z")

</div>

Thank you!  
In fact I wanted to display things like below,

```
----- Iteration = 47 -> Log Likelihood = -5.158964
Sigma = 0.10265 +- 0.00199
Mixture Label : 1 | 2 |
Weight = 0.20000 | 0.80000 |
Mu_k = 0.63695 +- 0.00333 | 0.30996 +- 0.00484 |
Sig Mu_k = 0.03692 +- 0.00201 | 0.05363 +- 0.00336 |
Mu_V = 20.01389 +- 0.12476 | 20.01389 +- 0.12476 |
Sig Mu_V = 1.95679 +- 0.08312 | 1.95679 +- 0.08312 |
Mu_k MC acc rate = 2.880% | 9.941% |
Mu_V MC acc rate = 5.731% | 5.731% |
-----------------------------------------------------------------------------

```

it is gaussian mixture model, k=1,2.  
For each k, I want to show all the results. I want to show them horizontally than vertically.  
Because for each k if I need 10 lines, for k=10, if I show them vertically it will take 500 lines which is very inconvenient. But if I show them horizontally, it will only take 10 lines, and it is wide, but is conveneint.  
The thing is currently done using Fortran’s format IO, I am still trying to get used to Julia.

---

<div class="post-metadata">

**Author:** ![CRquantum](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/crquantum/32/27824_2.png) [@CRquantum](https://discourse.julialang.org/u/CRquantum)\
**Post date:** [August 6, 2021, 8:10am UTC](https://discourse.julialang.org/t/how-to-display-the-elements-of-1d-array-in-one-line/65925/6 "2021-08-06T08:10:35Z")

</div>

Nice Thank you!

---

<div class="post-metadata">

**Author:** ![CRquantum](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/crquantum/32/27824_2.png) [@CRquantum](https://discourse.julialang.org/u/CRquantum)\
**Post date:** [August 6, 2021, 8:12am UTC](https://discourse.julialang.org/t/how-to-display-the-elements-of-1d-array-in-one-line/65925/7 "2021-08-06T08:12:00Z")

</div>

I have edited my question. Sorry I always ask my question in a very sloppy way:P  
Anyway, thank you very much indeed!
