Course Content

Mathematics for Data Analysis and Modeling

## Mathematics for Data Analysis and Modeling

# Numerical Operations on Vectors and Matrices

## Numerical operations on vectors

In Python, numerical operations on vectors can be performed using various libraries such as NumPy. NumPy provides efficient and convenient functions for vectorized operations, making it easy to perform calculations on vectors.

Here are some common numerical operations on vectors, along with examples in Python:

### Addition

Adding two vectors together element-wise.

### Subtraction

Subtracting one vector from another element-wise.

### Scalar Multiplication

Multiplying a vector by a scalar value.

### Dot Product

Computing the dot product between two vectors.

The dot product of two vectors is a mathematical operation that yields a scalar value.
The dot product of two vectors `u`

and `v`

is calculated by taking the sum of the products of their corresponding components:

`u · v = u₁ * v₁ + u₂ * v₂ + u₃ * v₃ + ... + uₙ * vₙ`

## Operations on matrices

Now let's consider numerical operations on **matrices**.

### Addition and subtraction

Matrices and vectors of the same shape can be added or subtracted element-wise.

### Scalar Multiplication and Division

Each element of a matrix or vector can be multiplied or divided by a scalar value. Example in Python:

### Matrix Multiplication

Multiplication of two matrices is a binary operation combining two matrices to produce a new matrix. To compute the result of the multiplication of two matrices, **the number of columns in the first matrix must equal the number of rows in the second matrix**.

The dot product of matrices is calculated by taking the dot product of corresponding rows from the first matrix and columns from the second matrix.

The resulting matrix will **have the same number of rows as the first matrix and the same number of columns as the second matrix**.
The process of matrix multiplication can be visualized as follows:

## Example

Note

Pay attention that matrix multiplication operation is not commutative. In general case,

`A * B != B * A`

.

Everything was clear?