LoginSignup
0

More than 5 years have passed since last update.

Julia 2✖︎2配列でappend!できない場合 MethodError

Last updated at Posted at 2018-12-04

ver.1.0.2を使用.
参考: https://docs.julialang.org/en/v1/manual/arrays/

Array{Float64,1}の場合

すんなりappend!できる.

julia> hoge = zeros(2);foo = ones(2)
2-element Array{Float64,1}:
 1.0
 1.0

julia> append!(hoge,foo)
4-element Array{Float64,1}:
 0.0
 0.0
 1.0
 1.0

append!は破壊的演算なので,hogeが変わっている.

julia> hoge
4-element Array{Float64,1}:
 0.0
 0.0
 1.0
 1.0

Array{Float64,2}の場合

append!ではできません.

julia> hoge = zeros(2,2);foo = ones(2,2)
2×2 Array{Float64,2}:
 1.0  1.0
 1.0  1.0

julia> append!(hoge,foo)
ERROR: MethodError: no method matching append!(::Array{Float64,2}, ::Array{Float64,2})
Closest candidates are:
  append!(::Array{T,1} where T, ::Any) at array.jl:902
Stacktrace:
 [1] top-level scope at none:0

解決策

julia> vcat(hoge,foo)
4×2 Array{Float64,2}:
 0.0  0.0
 0.0  0.0
 1.0  1.0
 1.0  1.0

vcatは非破壊的

julia> hoge
2×2 Array{Float64,2}:
 0.0  0.0
 0.0  0.0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0