Matrix is a two-dimensional data structure arranged in rows and columns.
A matrix is often represented as an array of arrays.
For example:
1 2 3
4 5 6
7 8 9Matrices are useful for:
- Grids
- Images
- Tables of numeric data
- Graph representations
- Linear algebra
Common operations include:
- Reading a cell by row and column
- Iterating over rows
- Iterating over columns
- Transposing rows and columns
In programming, a matrix cell is often accessed with two indexes, such as matrix[row][column].
flowchart TD Matrix["matrix"] --> Row0["row 0: 1 2 3"] Matrix --> Row1["row 1: 4 5 6"] Matrix --> Row2["row 2: 7 8 9"]
Anki
id: matrix-definition deck: Computer Science::Data Structures tags: data-structures matrix
Q: What kind of data naturally fits in a matrix? A: Grid-like data such as images, game boards, spreadsheets, or numeric tables.
id: matrix-indexing deck: Computer Science::Data Structures tags: data-structures matrix
Q: In matrix[row][column], what do the two indexes usually mean?
A: The first index chooses the row, and the second index chooses the column.