A simple question: By definition, does an m x n
matrix have m
rows and n
columns, or is it vice versa?

- 1,035
-
Yes it's always "{number of rows} by {number of columns}" – Colonel Panic Feb 18 '15 at 16:15
-
2You can name the variables how you like though. Curiously "m by n matrix" is about twice as common as "n by m matrix" in Google search results. – Colonel Panic Feb 18 '15 at 16:19
-
2@ColonelPanic, that's probably because for a matrix $A$ operating on an $n$ dimensional vector $\mathcal{x}$ (i.e. $A \mathbf{x} = \mathbf{y}$) $\mathbf{y}$ is $m$ dimensional. In other words, it puts the input dimension before the output dimension alphabetically. – Shep Apr 03 '15 at 01:42
5 Answers
-
-
3All the textbooks i have read (both cs and math) have used this notation. For example, Strang's Introduction to Linear Algebra 4th. – James Sep 06 '12 at 02:17
-
-
1
-
How come accessing elements usually start with column, e.g. in Numpy. This is confusing. – Ivan Balashov Jun 20 '16 at 06:24
-
1@IvanBalashov In Numpy the first dimension is the row, not the column. – bfontaine Oct 22 '16 at 07:36
-
-
-
I remember this with "mn" being in alphabetical order AND visually on the matrix "rows" are labelled first on the left, and "columns" are labelled second on top to the right, the same way we read in English, from left to right, giving the order rows x columns. – Paul Parker Sep 14 '21 at 00:59
Always check and make sure you have the right convention for the occasion. Usually m x n is rows x columns. I like to remember this as being in REVERSE alphabetical order - Rows by Columns, or R first then C. However, in Boyce & DiPrima's book "Elementary Differential Equations and Boundary Value Problems" an m x n matrix has m vertical columns and n horizontal rows.
However, when addressing elements within a matrix, it's the opposite. The element "a sub i,j" references the element in the ith row and jth column.
Lesson? Always check to make sure you have the correct convention!

- 21
-
1
-
@RobertLugg exactly. x columns by y rows. i columns by j rows. Then algebra with the 'hold my beer' goes with m rows by n columns. I almost have feelings about this... – AndrewBenjamin Apr 19 '23 at 13:15
I suggest you always to check the notation on the book which you are using. I found sometimes this notation with different meaning. In advanced books, for example. Even the notation for linear maps as matrices. Sometimes they write $xT$.

- 6,416
- 3
- 25
- 45
-
-
It is the notation for the image of $x$ by the linear map $T$. Usually we write $T(x)$ or $Tx$. – Sigur Sep 06 '12 at 02:38
Yes... It's m-rows and n-Columns.
Here is an example, how you can generate and read a matrix in JavaScript :)
let createMatrix = (m, n) => {
let [row, column] = [[], []],
rowColumn = m * n
for (let i = 1; i <= rowColumn; i++) {
column.push(i)
if (i % n === 0) {
row.push(column)
column = []
}
}
return row
}
let setColorForEachElement = (matrix, colors) => {
let row = matrix.map(row => {
let column = row.map((column, key) => {
return { number: column, color: colors[key] }
})
return column
})
return row
}
const colors = ['red', 'green', 'blue', 'purple', 'brown', 'yellow', 'orange', 'grey']
const matrix = createMatrix(6, 8)
const colorApi = setColorForEachElement(matrix, colors)
let table ='<table>'
colorApi.forEach(row => {
table+='<tr>'
row.forEach(column => table +=`<td style='background: ${column.color};'>${column.number}<td>` )
table+='</tr>'
})
document.write(table);
Sometimes one can forget which number maps to row or column numbers. However, we don't need remember it.
Just remember the Matrix multiplication:
For Matrix A, B, and R = A × B, we have
A (m × p) × B (p × n) = R (m × n)
Now from the definition of multiplication, you will easily find that a (m × n) matrix has m rows and n columns.