# How to make 1×n Array{String, 2} from n-element Array{String, 1}?

**URL:** <https://discourse.julialang.org/t/how-to-make-1xn-array-string-2-from-n-element-array-string-1/11138>\
**Category:** General Usage\
**Tags:** question, plotting\
**Created:** [May 25, 2018, 7:29am UTC](https://discourse.julialang.org/t/how-to-make-1xn-array-string-2-from-n-element-array-string-1/11138 "2018-05-25T07:29:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![paalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paalon/32/5784_2.png) [@paalon](https://discourse.julialang.org/u/paalon)\
**Post date:** [May 25, 2018, 7:29am UTC](https://discourse.julialang.org/t/how-to-make-1xn-array-string-2-from-n-element-array-string-1/11138/1 "2018-05-25T07:29:09Z")

</div>

I am using Plots and it requires to be set labels as 1×n Array{String, 2} but I want to make the labels automatically. I can get n-element Array{String, 1} but I cannot find how to convert this to 1×n Array{String, 2}. Can anyone help?

---

<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:** [May 25, 2018, 7:36am UTC](https://discourse.julialang.org/t/how-to-make-1xn-array-string-2-from-n-element-array-string-1/11138/3 "2018-05-25T07:36:19Z")

</div>

```julia
julia> reshape(["a","b","c"], 1, :)
1×3 Array{String,2}:
 "a" "b" "c"

```

---

<div class="post-metadata">

**Author:** ![paalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paalon/32/5784_2.png) [@paalon](https://discourse.julialang.org/u/paalon)\
**Post date:** [May 25, 2018, 7:40am UTC](https://discourse.julialang.org/t/how-to-make-1xn-array-string-2-from-n-element-array-string-1/11138/4 "2018-05-25T07:40:33Z")

</div>

I stuck this for a long. Thanks a lot!

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [May 25, 2018, 7:44am UTC](https://discourse.julialang.org/t/how-to-make-1xn-array-string-2-from-n-element-array-string-1/11138/5 "2018-05-25T07:44:39Z")

</div>

or `hcat(x...)` which I find easier to remember (it is a bit slower though).

---

<div class="post-metadata">

**Author:** ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)\
**Post date:** [May 25, 2018, 8:47am UTC](https://discourse.julialang.org/t/how-to-make-1xn-array-string-2-from-n-element-array-string-1/11138/6 "2018-05-25T08:47:25Z")

</div>

There’s also `permutedims`:

```julia

julia> sa = ["a","b","c"]
3-element Array{String,1}:
 "a"
 "b"
 "c"

julia> permutedims(sa)
1×3 Array{String,2}:
 "a" "b" "c"

```

`permutedims(sa)` seems to be about 5x faster than `reshape(sa, 1, :)`, though the difference probably doesn’t matter in this case.

---

<div class="post-metadata">

**Author:** ![paalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paalon/32/5784_2.png) [@paalon](https://discourse.julialang.org/u/paalon)\
**Post date:** [May 25, 2018, 8:53am UTC](https://discourse.julialang.org/t/how-to-make-1xn-array-string-2-from-n-element-array-string-1/11138/7 "2018-05-25T08:53:53Z")

</div>

I cant permutedims. What version is your Julia? I’m using 0.6.2.

```julia
julia> sa = ["a", "b", "c"]
3-element Array{String,1}:
 "a"
 "b"
 "c"

julia> permutedims(sa)
ERROR: MethodError: no method matching permutedims(::Array{String,1})
Closest candidates are:
  permutedims(::Union{Base.ReshapedArray{T,N,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{DenseArray, SubArray{T,N,P,I,true} where I<:Tuple{Union{Base.Slice, UnitRange},Vararg{Any,N} where N} where P where N where T}, DenseArray{T,N}, SubArray{T,N,A,I,L} where L} where I<:Tuple{Vararg{Union{Base.AbstractCartesianIndex, Int64, Range{Int64}},N} where N} where A<:Union{Base.ReshapedArray{T,N,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{DenseArray, SubArray{T,N,P,I,true} where I<:Tuple{Union{Base.Slice, UnitRange},Vararg{Any,N} where N} where P where N where T} where N where T, DenseArray} where N where T, ::Any) at multidimensional.jl:1292
  permutedims(::AbstractArray, ::Any) at permuteddimsarray.jl:116

```

---

<div class="post-metadata">

**Author:** ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)\
**Post date:** [May 25, 2018, 9:05am UTC](https://discourse.julialang.org/t/how-to-make-1xn-array-string-2-from-n-element-array-string-1/11138/8 "2018-05-25T09:05:21Z")

</div>

Huh, it’s a v0.7 change [apparently](https://github.com/JuliaLang/julia/blob/master/NEWS.md):

> permutedims(m::AbstractMatrix) is now short for permutedims(m, (2,1)), and is now a more convenient way of making a “shallow transpose” of a 2D array. This is the recommended approach for manipulating arrays of data, rather than the recursively defined, linear-algebra function transpose. Similarly, permutedims(v::AbstractVector) will create a row matrix (#[24839](https://github.com/JuliaLang/julia/issues/24839)).

It was on 0.7 that I tried that, I too get this error on 0.6. `permutedims` on 0.6 doesn’t seem to have a way of changing a 1-D array into 2-D, so reshape is probably the way to go.

---

<div class="post-metadata">

**Author:** ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)\
**Post date:** [May 25, 2018, 11:04am UTC](https://discourse.julialang.org/t/how-to-make-1xn-array-string-2-from-n-element-array-string-1/11138/9 "2018-05-25T11:04:53Z")

</div>

This short thread had been so educational. I didn’t know about permutedims (well, I did at one point and then forgot), and I _also_ didn’t know you could do `:` in reshape - that’s great!
