I'm trying to make a vector of 3D points in Julia, which I currently have as vectors themselves. However, I cannot figure out how to get these vectors into a vector. My minimal example to reproduce the error is:
foo = rand(3) #Vector Float64, 3
bar = Vector{Float64}[] #Vector Array{Float64,1} 0
append!(bar,foo) #Throws an error
Which throws the error at the last line
`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
Is there a way to do this, or am I missing something that prevents such a structure? Should I be using matrices instead? I haven't so far since I want to iterate over the points, not transform them in bulk.
I think you're looking for
push!(bar, foo)
append
takes the second paramater as a collection, so each element of foo
(each one an Int
) will fail to be added. You can do:
append!(bar,[foo for i in 1:1])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With