julia - InexactError: Int64(::Float64)

标签 julia

我仍在学习 Julia 语言,但出现此错误。我正在编写一个蚊子种群模型,我正在尝试运行我的主要功能 100 次。此主函数使用许多其他函数来计算子种群水平。


# Importing KNMI data 
xf = XLSX.readxlsx("C:/Scriptie_mosquitoes/knmi_csv.xlsx")
sh = xf["knmi_csv"]
temperature = sh["B3:B368"]
precip = sh["F3:F368"]

subpopulation_amount = 100

imat_list1 = zeros(100,length(temperature))
imat_list = Array{Float64}(imat_list1)

adul_list1 = zeros(100,length(temperature))
adul_list = Array{Float64}(adul_list1)

egg_list1 = zeros(100,length(temperature))
egg_list = Array{Float64}(egg_list1)

diaegg_list1 = zeros(100,length(temperature))
diaegg_list = Array{Float64}(diaegg_list1)

imat_list[1] = 100.0
adul_list[1] = 1000.0
egg_list[1] = 100.0
diaegg_list[1] = 100.0

for counter = 1:1:subpopulation_amount
    u = Distributions.Normal()
    temp_change = rand(u)
    tempa = temperature .+ temp_change
    println(tempa)

    e = Distributions.Normal()
    precip_change = rand(e)
    println("hallo", precip_change)


    println(counter,tempa,precip,precip_change)
    main(counter,tempa::Array{Float64,2},precip::Array{Any,2},precip_change::Float64,imat_list::Array{Float64,2},adul_list::Array{Float64,2},egg_list::Array{Float64,2},diaegg_list::Array{Float64,2})
end

但是我得到了这个错误,我试图用所有的 Float64 stuf 来修复它。不幸的是,我不工作。我希望你们中的一些人看到了这个问题,或者可以帮助我理解错误信息。
ERROR: InexactError: Int64(87.39533010546728)
Stacktrace:
 [1] Int64 at .\float.jl:710 [inlined]
 [2] convert at .\number.jl:7 [inlined]
 [3] setindex! at .\array.jl:825 [inlined]
 [4] main(::Int64, ::Array{Float64,2}, ::Array{Any,2}, ::Float64, ::Array{Float64,2}, ::Array{Float64,2}, ::Array{Float64,2}, ::Array{Float64,2}) at .\REPL[905]:19
 [5] top-level scope at .\REPL[938]:10

最佳答案

您可以查看 InexactError 的文档。通过输入 ?InexactError :

help?> InexactError
search: InexactError

  InexactError(name::Symbol, T, val)

  Cannot exactly convert val to type T in a method of function name.

我认为这很好地解释了它。没有Int64表示值 87.39533010546728 .

您有多种选择。查看他们的帮助以了解有关他们的更多信息:
julia> trunc(Int, 87.39533010546728)
87

julia> Int(round(87.39533010546728))
87

julia> Int(floor(87.39533010546728))
87

关于julia - InexactError: Int64(::Float64),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62341038/

相关文章:

dataframe - 如何使用 Julia 通过循环生成多个 DataFrame

julia - 在 Julia 中处理大数

julia - 如何遍历字符串中的行?

proxy - Julia 连接到代理后面的服务器

Julia 密谋 : how to add both a single point and a list of points to a scatter plot

dataframe - 参数错误: columns argument must be a vector of AbstractVector objects

julia - 如何在 Julia 中使用 vegas 计算具有无限边界的高维多重积分

julia - 如何在 Julia 中对多个值使用 `endswith()`?

function - 如何使用线性回归插值方法在 Julia 中查找变量?

julia - 访问另一个函数中定义的函数