function random_step(x, dx)
num=randn(1)
return x + num*dx
end
random_step(1, 1)
Run Code Online (Sandbox Code Playgroud)
运行此代码给了我:
julia> random_step(1, 1)
ERROR: MethodError: no method matching +(::Int32, ::Array{Float64,1})
For element-wise addition, use broadcasting with dot syntax: scalar .+ array
Closest candidates are:
+(::Any, ::Any, ::Any, ::Any...) at operators.jl:538
+(::T, ::T) where T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8} at int.jl:86
+(::Union{Int16, Int32, Int8}, ::BigInt) at gmp.jl:531
...
Stacktrace:
[1] random_step(::Int32, ::Int32) at .\REPL[1]:3
[2] top-level scope at REPL[2]:1
Run Code Online (Sandbox Code Playgroud)
所以我假设当我输入 1 时,数据类型不是 randn 的 …
julia ×1