I have been almost always confused with rows and columns of a Matrix. It is not because it is difficult concept.. it was just confusing. If you have similar problem, look at these illustration and just take a picture onto your brain and just play it back in the form of image on your brain.
This page fixes the two conventions that every other matrix page relies on. The first is the direction of rows and columns. The second is the order of the two indices that point to one element.
- How do rows and columns run in a matrix ?
- How is one element of a matrix indexed ?
- Example
- How do programming tools count rows and columns ?
How do rows and columns run in a matrix ?
Let's fix the directions first, because every later rule depends on them. A row runs horizontally, from left to right. A column runs vertically, from top to bottom. The illustration below shows both for a 3 x 3 matrix, with the rows on the left and the columns on the right.

Every element of a row has the same first index : Row 2 holds a21, a22 and a23, and only the second index changes along it.Every element of a column has the same second index : the middle column holds a12, a22 and a32, and only the first index changes down it.The column labels in the picture all read Column 1 : read them as Column 1, Column 2 and Column 3 from left to right.The size also names the rows first : an m x n matrix has m rows and n columns, so a 2 x 3 matrix has 2 rows of 3 elements each.
The same order carries over to vectors. A row vector is a matrix with one row, so its size is 1 x n. A column vector is a matrix with one column, so its size is m x 1. The difference matters as soon as you multiply. The product of a 1 x 3 row vector and a 3 x 1 column vector is a single number, while the product in the other order is a 3 x 3 matrix.
How is one element of a matrix indexed ?
Once the directions are fixed, pointing to one element needs two numbers. The rule is the same in every textbook and every tool: the row index comes first, and the column index comes second.
When we refer to (point to) a certain elements of a Matrix, we usually use a symbol as follows. Again, I have been frequently confused with which subscription indicate Row and which one indicate a Column. Also, just take the picture of this on your brain.

i is the row number : it counts from 1 at the top row down to m.j is the column number : it counts from 1 at the left column across to n.The order never changes : a23 is row 2, column 3, and a32 is row 3, column 2. The two are different elements, and they hold the same value only when the matrix is symmetric.
Because of the difficulties of writing mathematical symbols in a plain text format, I will represent this symbol as a(i,j) in this page just for easy writing.
![]()
The index pair also gives short names to whole groups of elements. The elements with i = j form the main diagonal. The elements with i < j lie above the diagonal, and the elements with i > j lie below it. The transpose AT swaps the two indices, so the element in row i, column j of AT is aji.
Example
For a practice, let's suppose that we have a simple 3 x 3 matrix as shown below. (If you are not familiar with what 3 x 3 matrix mean, refer to Matrix Dimension page)

What is a(1,1) ? => It indicate Row 1 and Col 1 meaning '1'
What is a(2,3) ? => It indicate Row 2 and Col 3 meaning '6'
What is a(3,2) ? => It indicate Row 3 and Col 2 meaning '8'
Let's read the same matrix by rows and by columns. Row 2 is 4, 5, 6, and column 3 is 3, 6, 9. The main diagonal is 1, 5, 9. For this particular matrix, every element follows one formula, a(i,j) = 3(i - 1) + j, because each row starts 3 higher than the row above it. For example, a(3,2) = 3 x 2 + 2 = 8, which matches the answer above.
The transpose gives a quick test of the index order. AT has the rows of A as its columns, so the element in row 3, column 2 of AT is a(2,3) = 6, not 8.
Read the row index first : a(2,3) means go down to row 2, then across to column 3.Swapping the indices changes the element : a(2,3) = 6 while a(3,2) = 8.
How do programming tools count rows and columns ?
Software keeps the row-first order, but it does not always start counting at 1. This is the most common source of off-by-one errors when a formula moves from paper into code.
Matlab and Octave count from 1, exactly like the math notation. For the matrix in the example, A(2,3) returns 6, A(2,:) returns the whole row 2, and A(:,3) returns the whole column 3. Python with numpy counts from 0. So the same element is A[1,2], the row is A[1,:], and the column is A[:,2].
The two tools also use different orders when they flatten a matrix into one list. Matlab stores a matrix column by column, so A(:) is 1, 4, 7, 2, 5, 8, 3, 6, 9, and the single index A(8) returns 6. The numpy default is row by row, so A.flatten() is 1 to 9 in order, and index 5 returns 6. For an m x n matrix, the Matlab linear index of a(i,j) is (j - 1) x m + i. The Column Selection Vector page shows how to pick whole columns and rows with a matrix product instead of an index.
The row still comes first in code : both A(i,j) in Matlab and A[i-1, j-1] in numpy put the row index first.Check the start index when you port a formula : the math a(i,j) is A(i,j) in Matlab but A[i-1, j-1] in numpy.Check the storage order when you reshape : Matlab reshape fills column by column and numpy reshape fills row by row, so the same call arranges the elements differently.