Best way to convert Vector to Matrix in Julia?

Suppose I have a vtype variable Vector.

What is the best / fastest way to just convert it to a view Matrix(for some reason)?

To clarify, v''complete the task, but the best way to do this?

+4
source share
2 answers

v[:,:]probably the clearest way to do this.

For example:

julia> v=[1,2,3]
3-element Array{Int64,1}:
1
2
3

julia> m=v[:,:]
3x1 Array{Int64,2}:
1
2
3

julia> ndims(m)
2
+6
source

Reform should be the most effective. From the docs:

(A, dims): , , . , .

julia> v = rand(3)
3-element Array{Float64,1}:
 0.690673 
 0.392635 
 0.0519467

julia> reshape(v, length(v), 1)
3x1 Array{Float64,2}:
 0.690673 
 0.392635 
 0.0519467
+11

Source: https://habr.com/ru/post/1622765/


All Articles