【问题标题】:using rand MethodError: no method matching isless(::Array{Float64,1}, ::Float64)使用 rand MethodError: 没有方法匹配 isless(::Array{Float64,1}, ::Float64)
【发布时间】:2021-04-14 15:51:26
【问题描述】:

如果我运行以下代码,

A = 0.2 
if rand(1)<0.85
   println(A)
end

错误是

MethodError: no method matching isless(::Array{Float64,1}, ::Float64)
Closest candidates are:

isless(!Matched::Missing, ::Any) at missing.jl:87

isless(!Matched::Float64, ::Float64) at float.jl:465

isless(!Matched::AbstractFloat, ::AbstractFloat) at operators.jl:165

我知道这是一个简单的代码。但不知道为什么 Julia 会抛出这个错误。请帮忙。

【问题讨论】:

    标签: if-statement julia


    【解决方案1】:

    你想要if rand()&lt;0.85rand(1) 生成 Vector 的 1 个元素 Float64rand() 生成一个Float64

    【讨论】:

      猜你喜欢
      • 2016-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-05
      • 2019-09-29
      • 2017-06-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多