将元素推送到矩阵数组

ara*_*van 1 arrays julia

假设你想拥有一个矩阵数组并在for循环中迭代并在每个循环中添加一个矩阵到数组中,你可以在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 ...
Run Code Online (Sandbox Code Playgroud)

我收到这个错误!

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

Rah*_*hul 7

A ()是你错过的!

看一看

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}
Run Code Online (Sandbox Code Playgroud)