假设我有一个变量 v
类型Vector
.
将其转换为 Matrix
的最佳/最快方法是什么?代表(无论出于何种原因)?
为了澄清,v''
会做这项工作,但这是最好的方法吗?
最佳答案
reshape 应该是最有效的。从文档:
reshape(A, dims): Create an array with the same data as the given array, but with different dimensions. An implementation for a particular type of array may choose whether the data is copied or shared.
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
关于arrays - 在 Julia 中将 Vector 转换为 Matrix 的最佳方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34595122/