View Full Version : Array.....what is a row & what is a column?
Hello,
I'm currently reading "Complete Maya Programming" by David Gould.
I'm confused about what is a row & what is a column, can some one advise me on this using the below example................
This is from P.74:
Single Dimentional Array that holds twodemensional data:
int $pixs[] = { 1, 2, 3, 4, 5, 6, 7, 8} ;
To find out what the single array index is that corresponds to a given row and column, the following formula is used:
index = row x number_of_columns + column
All indices are base 0. So to access row 1 (second row), column 3 (fourth column), you would do the following:
int $nCols = 4
int $index = 1 * $nCols + 3;
print $pixs[$index];
// Result: 8
Thanks
Fess


westiemad
10072005, 06:39 PM
row = [1,2,3,4]
[1
column = ,2
,3
,4]
i think he is talking about the fact that you can build a 2d array from values, e.g. a matrix and you can find the position in the array of the value. So to take his example and the one above you'd make it like this
[1,2,3,4] (The [ would stretch across both.)
5,6,7,8
westiemad,
Thanks for responding.
This book was going well with "explaination" and all of a sudden I turned the page and he starts throwing all this complex code at me without details of "how & why"........sigh.
I simple don't understand the defination of "column"
using this as a example:
martix $m[2][4] = << 3, 4, 6, 7; 3, 9, 0,1 >>; (okay, the matirx $m has 2 rows, first row is 3,4,6,7 and second rown is 3, 9, 0, 1 right?) Where or what the heck are the colums?
print ( $m [0][0] ); // Result: 3 (this is saying print print row 0 and column 0, how did it get "3"?)
print ( $m [1][3] ); // Result: 1 (this is saying print print row1 and column 2, row 1 is 3, 4, 6 7 and column is ????)
Thank you
Fess
goleafsgo
10082005, 10:00 PM
3 4 6 7
3 9 0 1
Above is your example...so (3,4,6,7) is the first row and (3,3) is the first column, (4,9) is the second column, (6,0) is the third column and (7,1) is the fourth column.
The element that is in the first row and first column would be 3...which is what you are asking for when you say $m[0][0]. If you print $m[1][2] you should get 0.
Does that help at all?
westiemad
10092005, 10:50 AM
columns are the numbers from top to bottom, like goleafsgo said
row
>
1 2 3 4 
5 6 7 8  column
9 1 2 5 V
Just think of column like a column in real life, holding up part of a building, its just soming that goes up and down at a position.
at the moment, don't worry too much about matrices, yes they are important for transformations, converting points from one space to another etc, but you really won't use them too much (or at least I haven't yet).
Here is a useful page:
http://chortle.ccsu.edu/VectorLessons/vmch13/vmch13_1.html
goleafsgo,
Your explaination did the trick. I understand the whole row/column layout now. Put that together with indices based 0, it all makes sense :thumbsup:
westiemad,
I'll check that link out, thanks. Cool way to think about "rows" & "columns"
Thank you
Fess
thematt
10142005, 08:40 AM
westiemad what a great LINK !!!
Thanks a million for that one..that site is awsome
cheers
CGTalk Moderation
10142005, 08:40 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©20002014, Jelsoft Enterprises Ltd.