Matrices:
A matrix is a two-dimensional array of numbers, symbols, or expressions arranged in rows and columns. Matrices are used in various mathematical and computational contexts, including linear algebra, statistics, and deep learning, to represent data and perform operations like addition, subtraction, multiplication, and more.
Example:
3 × 4 matrix, where 3 × 4 is the order of the matrix
$$A =
\begin{bmatrix}
a_{00} & a_{01} & a_{02} & a_{03}\\
a_{10} & a_{11} & a_{12} & a_{13}\\
a_{20} & a_{21} & a_{22} & a_{23}\\
a_{30} & a_{31} & a_{32} & a_{33}
\end{bmatrix}$$
Sample Code in NumPy:
You can create and manipulate matrices in Python using the NumPy library. Here’s a sample code to create the matrix A and perform some basic operations:
import numpy as np
# Create a 2x3 matrix A
A = np.array([[1, 2, 3],
[4, 5, 6]])
# Accessing elements in the matrix
print("Element at row 1, column 2:", A[0, 1]) # Outputs: 2
# Matrix addition
B = np.array([[7, 8, 9],
[10, 11, 12]])
C = A + B
print("Matrix C (A + B):")
print(C)
# Matrix multiplication
D = np.array([[1, 2],
[3, 4],
[5, 6]])
E = np.array([[7, 8],
[9, 10],
[11, 12]])
F = np.dot(D, E)
print("Matrix F (D * E):")
print(F)This code demonstrates how to create matrices, access elements, perform matrix addition, and matrix multiplication using NumPy. Matrices are fundamental in deep learning as they are often used to represent features, weights, and activations in neural networks.