CIs = CartesianIndices((2, 3, 4))
# 配列からも生成できる
#X = rand(2, 3, 4)
#CIs = CartesianIndices(X)
2×3×4 CartesianIndices{3,Tuple{Base.OneTo{Int64},Base.OneTo{Int64},Base.OneTo{Int64}}}: [:, :, 1] = CartesianIndex(1, 1, 1) CartesianIndex(1, 2, 1) CartesianIndex(1, 3, 1) CartesianIndex(2, 1, 1) CartesianIndex(2, 2, 1) CartesianIndex(2, 3, 1) [:, :, 2] = CartesianIndex(1, 1, 2) CartesianIndex(1, 2, 2) CartesianIndex(1, 3, 2) CartesianIndex(2, 1, 2) CartesianIndex(2, 2, 2) CartesianIndex(2, 3, 2) [:, :, 3] = CartesianIndex(1, 1, 3) CartesianIndex(1, 2, 3) CartesianIndex(1, 3, 3) CartesianIndex(2, 1, 3) CartesianIndex(2, 2, 3) CartesianIndex(2, 3, 3) [:, :, 4] = CartesianIndex(1, 1, 4) CartesianIndex(1, 2, 4) CartesianIndex(1, 3, 4) CartesianIndex(2, 1, 4) CartesianIndex(2, 2, 4) CartesianIndex(2, 3, 4)
# 逐次的に得られればよいなら
for CI in CIs
@show i, j, k = CI.I
end
(i, j, k) = CI.I = (1, 1, 1) (i, j, k) = CI.I = (2, 1, 1) (i, j, k) = CI.I = (1, 2, 1) (i, j, k) = CI.I = (2, 2, 1) (i, j, k) = CI.I = (1, 3, 1) (i, j, k) = CI.I = (2, 3, 1) (i, j, k) = CI.I = (1, 1, 2) (i, j, k) = CI.I = (2, 1, 2) (i, j, k) = CI.I = (1, 2, 2) (i, j, k) = CI.I = (2, 2, 2) (i, j, k) = CI.I = (1, 3, 2) (i, j, k) = CI.I = (2, 3, 2) (i, j, k) = CI.I = (1, 1, 3) (i, j, k) = CI.I = (2, 1, 3) (i, j, k) = CI.I = (1, 2, 3) (i, j, k) = CI.I = (2, 2, 3) (i, j, k) = CI.I = (1, 3, 3) (i, j, k) = CI.I = (2, 3, 3) (i, j, k) = CI.I = (1, 1, 4) (i, j, k) = CI.I = (2, 1, 4) (i, j, k) = CI.I = (1, 2, 4) (i, j, k) = CI.I = (2, 2, 4) (i, j, k) = CI.I = (1, 3, 4) (i, j, k) = CI.I = (2, 3, 4)
# タプルの配列として得たいなら
getproperty.(CIs, :I)
2×3×4 Array{Tuple{Int64,Int64,Int64},3}: [:, :, 1] = (1, 1, 1) (1, 2, 1) (1, 3, 1) (2, 1, 1) (2, 2, 1) (2, 3, 1) [:, :, 2] = (1, 1, 2) (1, 2, 2) (1, 3, 2) (2, 1, 2) (2, 2, 2) (2, 3, 2) [:, :, 3] = (1, 1, 3) (1, 2, 3) (1, 3, 3) (2, 1, 3) (2, 2, 3) (2, 3, 3) [:, :, 4] = (1, 1, 4) (1, 2, 4) (1, 3, 4) (2, 1, 4) (2, 2, 4) (2, 3, 4)