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

标签 arrays multidimensional-array julia

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

相关文章:

python - 将 ndarray 转换为二维数组,其中行是沿第一个轴的元素

statistics - Julia - describe() 函数显示不完整的汇总统计信息

java - 在数组的数组中查找模式

julia - 无法从 HTTP.get 读取文件

twitter - 读取包含 Twitter 表情符号描述的文件

jquery - 嵌套 jQuery.grep

Python - 求和 4D 数组

c++ - 以类似于初始化字符串文字的方式初始化 char 数组

Java 我的程序的数组没有显示任何值

Matlab:通过向量列表减去 3D 数组中的向量