# Vector Basics

**Scalars**

**Scalars**

Scalars are single numbers. Example: x ∈ R denotes that the scalar value x is a member of real valued numbers R.

## Vector

**Vector **in Machine Learning is a collection/array of numbers that corresponds to some features.

Example: [2,5,1] may be used to classify an apple where the first, second and third values represent features such as size, color and number of seeds in a fruit respectively.

Vector in Python can be represented as a NumPy array.

### Vector Arithmetic

Two vectors of equal length can be added, subtracted, divided or multiplied with each other to result in a new vector with the same length.

If `a = [a1, a2, a3]`

and b = `[b1, b2, b3]`

then the following operation will yield:

a) **Addition**: `c = [a1+b1, a2+b2, a3+b3]`

b) **Subtraction**: `c = [a1-b1, a2-b2, a3-b3]`

c) **Division**: `c = [a1/b1, a2/b2, a3/b3]`

d) **Multiplication**: `c = [a1*b1, a2*b2, a3*b3]`

### Vector Scalar Multiplication

Vector can be multiplied by a scalar value. This results in scaling the magnitude of a vector.

If `a = [a1, a2, a3]`

and `s = scalar`

**Vector Scalar Multiplication**: `c = [s*a1, s*a2, s*a3]`

### Vector Dot Product

Vector dot product is a number/value obtained by adding the multiplied elements of two vectors of the same length. Named after the dot(period) operator which describes it.

If `a = [a1, a2, a3]`

and `b = [b1, b2, b3]`

then

**Vector Dot Product**: `c = a . b = (a1*b1 + a2*b2 + a3*b3)`

Note: The dot product is an important tool for calculating vector projections, determining orthogonality, etc.

#### Alternate method: Vector Dot Product

Last updated