Elements In A Matrix

Prerequisites

Matrices Show

Elements In A Matrix

Introduction

  • Each element in a matrix can be uniquely referred to by its position.
  • Each element is appended a subscript containing its row position and column position respectively.
    • For example:
      x21
      refers to the element in row 2, column 1
  • The index of the row or column always starts at 1 (as opposed to programming where it starts at 0).

Example

LaTeX

\begin{bmatrix}
    x_{11}       & x_{12} & x_{13} & \dots & x_{1n} \\
    x_{21}       & x_{22} & x_{23} & \dots & x_{2n} \\
    \hdotsfor{5} \\
    x_{d1}       & x_{d2} & x_{d3} & \dots & x_{dn}
\end{bmatrix}

code (Python)

Note that we access element x21, however we refer to it as a[1, 0] because in programming indexes start at 0, not 1.
import numpy as np

a = np.matrix([[3, 6, 2], [5, 1, 10]])

print(a)  # prints [[ 3  6  2]
          #         [ 5  1 10]]


print(a[1, 0])  # prints '5'

a[1, 0] = 3
print(a[1, 0])  # prints '3'