朱莉娅:矢量矢量(阵列数组)

时间:2015-10-28 23:45:12

标签: julia

我试图在朱莉娅制作一个3D点矢量,我现在将它作为矢量本身。但是,我无法弄清楚如何将这些向量转换为向量。我重现错误的最小例子是:

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

有没有办法做到这一点,或者我错过了阻止这种结构的东西?我应该使用矩阵吗?我还没有到目前为止,因为我想迭代这些点,而不是批量转换它们。

2 个答案:

答案 0 :(得分:9)

我认为你正在寻找

(removeIt 'u '(u e u e))

答案 1 :(得分:2)

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

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