【发布时间】:2017-04-23 23:44:54
【问题描述】:
我想将 (x,y) 坐标保存在不同个人访问的网格网络中。假设我有 1000 个人,网络规模为 x = 1:100 和 y=1:100。我正在使用Dict(),这是一个关于我想要做什么的示例代码:
individuals = 1:1000
x = 1:100
y = 1:100
function Visited_nodes()
nodes_of_inds =Dict{Int64, Array{Tuple{Int64, Int64}}}()
for ind in individuals
dum_array = Array{Tuple{Int64, Int64}}(0)
for i in x
for j in y
if rand()<0.2 # some conditions
push!(dum_array, (i,j))
end
end
end
nodes_of_inds[ind]=unique(dum_array)
end
return nodes_of_inds
end
@time nodes_of_inds = Visited_nodes()
# result: 1.742297 seconds (12.31 M allocations: 607.035 MB, 6.72% gc time)
但这不是有效的。我感谢任何建议如何提高效率。
【问题讨论】:
标签: arrays dictionary data-structures julia