将元素推送到矩阵数组

时间:2017-03-28 11:11:15

标签: arrays julia

假设你想要一个矩阵数组并迭代 一个for循环并在每个循环中添加一个矩阵到数组,afaik你可以在julia中这样做:

V = Array{Array{Float64,2},1}  
for i=1:nlevels
    img = imgread("/path/img.png")
    push!(V, img) # append!(img) doesn't work too 
end

MethodError: no method matching append!(::Type{Array{Array{Float64,2},1}}, ::Array{Float64,2})
Closest candidates are:
  append!(!Matched::Array{T,1}, ::Any) at collections.jl:21
  append!(!Matched::CatIndices.BidirectionalVector{T}, ::Any) at ...

我收到此错误!

我在这里做错了什么! 如何在朱莉娅实现这一目标?

1 个答案:

答案 0 :(得分:6)

你错过了()

看看

julia> V = Array{Array{Float64,2},1}
Array{Array{Float64,2},1}

julia> typeof(V)
DataType

julia> V = Array{Array{Float64,2},1}()
0-element Array{Array{Float64,2},1}

julia> typeof(V)
Array{Array{Float64,2},1}