Traverse Nested Dict in Julia Lang

While I traverse the nested Dict in Julia, it gives this error:

ERROR: access to undefined reference
 in next at dict.jl:567

Here is the code where you can reproduce this error:

a = [0,19620,7291,32633,9,32513,42455,10045,31964,42455,11767,54]
b = [14318,16405,19,18913,19,8141,18958,12336,7,16588,17358,30]
d = Dict()
for aa in a
   for bb in b
     if ! haskey(d,aa)
        d[aa]=Dict()
     end
     d[aa][bb] = 0.5
   end
end 
for k1 in keys(d)
   s =0.0               
   for k2 in keys(d[k1])
     s+= d[k1][k2]
   end
   for k2 in keys(d[k1])
     d[k1][k2] = d[k1][k2] / s
   end
end

It is connected if a = [0,1] b = [0,1], it works fine.

---- Update -----

Actually, as long as the array b has 11 different elements, an error will occur. In addition, if

d[k1][k2] = d[k1][k2] / s

to become

d[k1][k2] = d[k1][k2] * s

or any other operations, the error will disappear.

Any ideas?

+4
source share
2 answers

This issue has now been fixed in the development branch and will be available in pre-releases immediately after they are updated.

See: https://github.com/JuliaLang/julia/pull/5894/files

+3
source

, , , d[k1] , . ( , .)

, ,

for k2 in collect(keys(d[k1]))
    d[k1][k2] = d[k1][k2] / s
end

( , .)

+2

Source: https://habr.com/ru/post/1528029/


All Articles