2
$\begingroup$

If I have a grid that I know is RxCxD in size, and I have number that corresponds to an element in that grid, and the grid is mapped in Row major format, how can I find out the ordered triplet that corresponds to the index that I know? that is

(i,j,k) = index

  • 0
    depth comes last2011-01-31

1 Answers 1

1

If $i$ increases most quickly, then $j$, then $k$ (so a 2x2x2 array would be 0,0,0 then 1,0,0, then 0,1,0 etc) and you start counting from 0, it is $i+Rj+RCk$. If you count from 1, it is $(i-1)+R(j-1)+RC(k-1)+1$

Going the other direction, if the element number is $N$, then $k=N/RC, j=(N-kRC)/R, i=N-kRC-jR$ where the divisions are integer. This assumes you start from 0.

  • 0
    So you have 3*rows*cols inputs and are calculating 9*rows*cols outputs? This needs some thought beyond array indexing.2011-02-01