Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Map array index to matrix

Tags:

arrays

c

openmp

My problem is this: I've an array with values from 0 to 8(a[9]=[0,1,2,....,8] and I would map the indexes of array to a matrix 3x3. This is useful for me to develop the "Broadcast Multiply Rolling" algorithm to make the product of two matrices. Thank to everyone

like image 440
sakuragi Avatar asked Jul 06 '26 20:07

sakuragi


1 Answers

If index is an index into a single-dimensional array of 9 elements, the array can be viewed as a two-dimensional 3x3 array with this:

int row = index / 3;
int column = index % 3;
int foo = array[row][column];
like image 70
Carey Gregory Avatar answered Jul 09 '26 11:07

Carey Gregory



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!