2015-10-28 94 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])