# Is there a way to transpose an array of Any? I have a \`12×500 Array{Any, 2}\` I want

**URL:** <https://discourse.julialang.org/t/is-there-a-way-to-transpose-an-array-of-any-i-have-a-12x500-array-any-2-i-want/56607>\
**Category:** General Usage\
**Created:** [March 6, 2021, 10:43am UTC](https://discourse.julialang.org/t/is-there-a-way-to-transpose-an-array-of-any-i-have-a-12x500-array-any-2-i-want/56607 "2021-03-06T10:43:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BridgeBot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bridgebot/32/21491_2.png) [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)\
**Post date:** [March 6, 2021, 10:43am UTC](https://discourse.julialang.org/t/is-there-a-way-to-transpose-an-array-of-any-i-have-a-12x500-array-any-2-i-want/56607/1 "2021-03-06T10:43:35Z")

</div>

Is there a way to transpose an array of Any? I have a `12×500 Array{Any,2}` I want it to be 500x12. If I do transpose it throws an error.

```julia
500×12 LinearAlgebra.Transpose{Any,Array{Any,2}}:
Error showing value of type LinearAlgebra.Transpose{Any,Array{Any,2}}:
ERROR: MethodError: no method matching transpose(::String)
Closest candidates are:
  transpose(::Missing) at missing.jl:100
  transpose(::Number) at number.jl:168
  transpose(::LinearAlgebra.Transpose) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\LinearAlgebra\src\adjtrans.jl:165

```

Note that the original poster on Slack cannot see your response here on Discourse. Consider _transcribing the appropriate answer back to Slack_, or pinging the poster here on Discourse so they can _follow this thread_.  
[(Original message :slack:)](https://julialang.slack.com/archives/C6A044SQH/p1615027402470400?thread_ts=1615027402.470400&cid=C6A044SQH) [(More Info)](https://github.com/JuliaCommunity/SlackBridge)

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [March 6, 2021, 2:54pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-transpose-an-array-of-any-i-have-a-12x500-array-any-2-i-want/56607/2 "2021-03-06T14:54:35Z")

</div>

In Julia, transpose is firmly rooted in linear algebra, but `permutedims` allows swapping of dimensions of any type of object. In other words,

```julia
julia> A = Any["hello" for i = 1:3, j=1:2]
3×2 Matrix{Any}:
 "hello" "hello"
 "hello" "hello"
 "hello" "hello"

julia> permutedims(A, (2, 1))
2×3 Matrix{Any}:
 "hello" "hello" "hello"
 "hello" "hello" "hello"

julia> transpose(A)
2×3 transpose(::Matrix{Any}) with eltype Any:
Error showing value of type Transpose{Any, Matrix{Any}}:
ERROR: MethodError: no method matching transpose(::String)
...

```

Why the distinction? Well, notice that the error message is telling you it’s trying to take `transpose(::String)`, which isn’t a defined operation. Why does it take the transpose of elements? It’s useful/necessary for generic linear algebra, as one can see with this vector-of-vectors:

```julia
julia> x = [[1,2], [10,11]]
2-element Vector{Vector{Int64}}:
 [1, 2]
 [10, 11]

julia> x'*x
226

julia> x[1]'*x[1] + x[2]'*x[2]
226

```

So not only does it reshape the container `x`, it also reshapes each element.

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [March 6, 2021, 3:39pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-transpose-an-array-of-any-i-have-a-12x500-array-any-2-i-want/56607/3 "2021-03-06T15:39:27Z")

</div>

For anyone looking to get involved in Julia development, here’s an issue to get your feet wet: [https://github.com/JuliaLang/julia/issues/39938](https://github.com/JuliaLang/julia/issues/39938)
