gpt4 book ai didi

arrays - 在 Julia 中将 Vector 转换为 Matrix 的最佳方法?

转载 作者:行者123 更新时间:2023-12-04 13:08:00 25 4
gpt4 key购买 nike

假设我有一个变量 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com