如何在 julia 的一个 for 循环中实现 5 维数组?
How can I implement 5 dimensional array in one for loop in julia?
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
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