julia - 不精确错误: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
解决方案
我们看不到 的代码main
。但是,您似乎正在使用Array
您拥有的其中一个 s 的值作为其参数,以用于索引代码中的某些向量。而且由于向量索引需要是整数,所以它失败了。很可能某些变量在您的主要位置错误 - 环顾[]
运营商。
调试时,您还可以尝试更改您的Arrays
toInt
元素并查看哪些更改导致问题停止。例如round.(Int, tempa)
等。
推荐阅读
- javascript - 将 Javascript ES6 Map() 传递给 MVC 控制器
- python - Django allauth 社交应用程序额外数据
- javascript - 获取 [innerHtml] 中的子 html 元素 | 用于突出显示文本的 Angular 6
- html - cPanel HTML 无法打开网站:403 Forbidden
- javascript - 从前端 AJAX 向节点 Js 中的给定路由发出 404/405 错误。本地主机 URL 不起作用
- rust - 在 Rust 中的线程之间共享只读对象?
- haskell - 为什么 fmap f xs = pure f <*> xs?
- android - 同一个 java 类有 2 种可能的 XML 布局
- python - 解析缩进字符串的优雅方法
- c++ - 在构造另一个对象期间存储对象名称