gpt4 book ai didi

algorithm - UndefVarError 未定义。我的代码中没有名为 st 的变量

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:26:10 26 4
gpt4 key购买 nike

返回矩阵中最小权重路径的路径元组的作业问题。但是代码给我一个错误:UndefVarError st not defined?

我试过在没有 for 循环的情况下运行程序,并只返回 s,这很有效。

function backtrack(pathweights)
s = size(pathweights)[1]
bestpath = []
a = argmin(pathweights[:, s])
push!(bestpath, (size(pathweights)[1]-1,a))

for j = size(pathweights)[1]:-1:1
b = argmin(pathweights[:, j])
for i = 1: size(pathweights)
if isdefined[pathweights[b+1,j-1]] &&
isdefined[pathweights[b-1,j-1]]
push!(bestpath, (min(pathweights[b, j-1],
pathweights[b-1,j-1], pathweights[b+1, j-1]), j))
else if isempty[pathweights[a+1,j-1]]
push!(bestpath, (min(pathweights[b-1, j-
1],pathweights[b, j-1]), j))
else
push!(bestpath, (min(pathweights[b, j-1],
pathweights[b+1,j-1]), j))
end
end
end
return bestpath
end

输入:路径权重 = [3 6 8 6 3 10 9 11 10 6 13 19 13 7 12 23 17 10 8 9 23 11 15 11 17]预期输出:最佳路径 = [(5,2), (4,3), (3,4), (2,5), (1,5)]

最佳答案

看起来您正在使用 Juno 并正在尝试评估包含错误的文件。

此错误已报告 here并由此修复 commit ,因此请更新至 Atom.jl 0.11.1(使用 using Pkg; Pkg.update() 并重试。

关于algorithm - UndefVarError 未定义。我的代码中没有名为 st 的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58451602/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com