Get 2D indices from a linear index
Use CartesianIndices((nrow, ncol))
, from this discourse post.
x = rand((7, 10))
CI = CartesianIndices((7, 10))
for i in 1:length(x)
r = CI[i][1]
c = CI[i][2]
@assert x[i] == x[r, c]
end
Use CartesianIndices((nrow, ncol))
, from this discourse post.
x = rand((7, 10))
CI = CartesianIndices((7, 10))
for i in 1:length(x)
r = CI[i][1]
c = CI[i][2]
@assert x[i] == x[r, c]
end