首页 > 解决方案 > 不精确错误:Int64(::Float64)

问题描述

我仍在学习 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

标签: julia

解决方案


我们看不到 的代码main。但是,您似乎正在使用Array您拥有的其中一个 s 的值作为其参数,以用于索引代码中的某些向量。而且由于向量索引需要是整数,所以它失败了。很可能某些变量在您的主要位置错误 - 环顾[]运营商。

调试时,您还可以尝试更改您的ArraystoInt元素并查看哪些更改导致问题停止。例如round.(Int, tempa)等。


推荐阅读