function prealloc()
situation=zeros(Int64,3^5,5);
i=1;
for north=0:2
for south=0:2
for east=0:2
for west=0:2
for current=0:2
situation[i,:]=[north, south, east, west, current]
i+=1
end
end
end
end
end
situation
end
prealloc()
如何在一个 for 循环上实现此代码 或仅在一个循环中 我如何使用嵌套循环来做到这一点
最佳答案
您可以将 for 循环合并为一个具有多个变量的循环。
function prealloc()
situation=zeros(Int64,3^5,5);
i=1;
for north=0:2, south=0:2, east=0:2, west=0:2, current=0:2
situation[i,:]=[north, south, east, west, current]
i+=1
end
situation
end
关于arrays - 如何在 julia 的一个 for 循环中实现 5 维数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28904008/