2015-10-28 96 views
2

我想在朱莉娅做一个向量,我现在已经作为向量本身。但是,我无法弄清楚如何将这些向量导入向量。我的小例子,重现错误是:朱莉娅:向量矢量(阵列阵列)

foo = rand(3) #Vector Float64, 3 
bar = Vector{Float64}[] #Vector Array{Float64,1} 0 
append!(bar,foo) #Throws an error 

这在最后一行

`convert` has no method matching convert(::Type{Array{Float64,1}}, ::Float64) 
in copy! at abstractarray.jl:197 
in append! at array.jl:478 
in include_string at loading.jl:97 
in include_string at C:\Users\Alex\.julia\v0.3\Jewel\src\eval.jl:36 
in anonymous at C:\Users\Alex\.julia\v0.3\Jewel\src\LightTable\eval.jl:68 
in handlecmd at C:\Users\Alex\.julia\v0.3\Jewel\src\LightTable/LightTable.jl:65 
in handlenext at C:\Users\Alex\.julia\v0.3\Jewel\src\LightTable/LightTable.jl:81 
in server at C:\Users\Alex\.julia\v0.3\Jewel\src\LightTable/LightTable.jl:22 
in server at C:\Users\Alex\.julia\v0.3\Jewel\src\Jewel.jl:18 
in include at boot.jl:245 
in include_from_node1 at loading.jl:128 
in process_options at client.jl:285 
in _start at client.jl:354 

引发错误有没有办法做到这一点,还是我失去了一些东西,以防止这样的结构?我应该使用矩阵吗?我还没有那么远,因为我想迭代点,而不是批量转换它们。

回答

8

我认为你正在寻找

push!(bar, foo) 
2

append将第二个参数作为一个集合,因此foo的每个元素(每个元素都是Int)将无法添加。你可以这样做:

append!(bar,[foo for i in 1:1])