I need to increase a matrix inside a function. But append!
works for vectors but doesn’t work for matrices
arg1=[1 2;3 4];
julia> append!(arg1, [5,6])
ERROR: MethodError: no method matching append!(::Array{Int64,2}, ::Array{Int64,1})
Closest candidates are:
append!(::Array{#s58,1} where #s58, ::AbstractArray{T,1} where T) at array.jl:895
append!(::Array{T,1} where T, ::Any) at array.jl:902
So I thought in this trick via reshape
but no luck either
julia> arg2=reshape(append!((reshape(arg1,:)), [5,6]), (2,3))
2×3 Array{Int64,2}:
1 2 5
3 4 6
julia> arg1
2×2 Array{Int64,2}:
1 2
3 4
So, even all those operations are inplace the input arg1
was not modified. This happens apparently because reshape
creates a new object that in spite sharing the same memory is different thing and is that new object that gets appended.