How to convert LinearAlgebra.Transpose into Array?

To answer (parts of?) your question, a Transposed matrix can be converted to a regular Matrix by calling the Matrix constructor (or, alternatively, by using copy)

julia> using LinearAlgebra

julia> a = reshape(rand(1:10, 9), (3,3))
3×3 Matrix{Int64}:
 8  5  10
 4  3  10
 9  3   3

julia> at = transpose(a)
3×3 transpose(::Matrix{Int64}) with eltype Int64:
  8   4  9
  5   3  3
 10  10  3

julia> b = Matrix(at)
3×3 Matrix{Int64}:
  8   4  9
  5   3  3
 10  10  3

julia> b = copy(at)
3×3 Matrix{Int64}:
  8   4  9
  5   3  3
 10  10  3

Assuming that your matrix doesn’t contain any missings, to get rid of the Union{Missing, Float64} you can call Matrix{Float64}(at) instead of Matrix(at)

julia> amissing = transpose(convert(Matrix{Union{Missing, Int64}}, a))
3×3 transpose(::Matrix{Union{Missing, Int64}}) with eltype Union{Missing, Int64}:
  8   4  9
  5   3  3
 10  10  3

julia> Matrix{Float64}(amissing)
3×3 Matrix{Float64}:
  8.0   4.0  9.0
  5.0   3.0  3.0
 10.0  10.0  3.0

Final note, just in case you aren’t familiar, Matrix{Float64} is just an alias for Array{Float64, 2}, i.e. it is the same thing.

julia> Matrix{Float64}
Matrix{Float64} (alias for Array{Float64, 2})
1 Like