A vector is a mathematical object that encodes length and direction. Formally, these are closed under an addition rule and a rule for multiplication by scalars - this is what we call a vector space, and it’s covered later. Scalars’ main use is for “scaling” a vector.
The study of vectors and rules to manipulate them is called linear algebra.
In general, vectors are special objects that can be added together and multiplied by scalars to produce another object of the same kind. From an abstract view, even polynomials are vectors because they satisfy those conditions. More examples include audio signals, geometrical vectors, and the type described below.
We represent vectors by a one dimensional array, referred to as a components, and is displayed in column or row form.
Geometrically, vectors represent coordinates within an n-dimensional space.
ex. 𝑣=(𝑣1𝑣2𝑣3𝑣𝑛)or𝑣=(𝑣1,𝑣2,𝑣3,,𝑣𝑛)𝑛, assuming 𝑣1,𝑣2,etc.
Here 𝑛 is the number of components of a vector, or the number of dimensions.
As an example, take n = 2. Then that represents the vector space 2. A vector that belongs to this vector space is 𝑣=(1,2) where the component along the first axis is 1 while on the second axis it’s two. Similarly, a vector belonging to vector space 𝑛 would have 𝑛 components, as seen in the above example.

Vector Algebra

some operations using vectors.

Addition and Subtraction

We can add or subtract vectors if they have the same dimensions.

𝑣1=(1,2)𝑣2=(3,4)𝑣1+𝑣2=(1+(3),2+4)=(2,6)𝑣1𝑣2=(1(3),24)=(4,2)

more generally,

𝑣1=(𝑥1,𝑥2,𝑥3,,𝑥𝑛)𝑣2=(𝑦1,𝑦2,𝑦3,,𝑦𝑛)𝑣1±𝑣2=(𝑥1±𝑦1,𝑥2±𝑦2,,𝑥𝑛±𝑦𝑛)

Dot product

For two vectors 𝑣1 and 𝑣2,

𝑣1=(𝑥1,𝑥2,𝑥3,,𝑥𝑛)𝑛𝑣2=(𝑦1,𝑦2,𝑦3,,𝑦𝑛)𝑛𝑣1𝑣2=(𝑥1𝑦1,𝑥2𝑦2,,𝑥𝑛𝑦𝑛)

or generally,

𝑣1𝑣2=𝑛𝑖=1𝑥𝑖𝑦𝑖

Keep in mind that the dot product is a scalar.

Length or magnitude of a vector

If a vector is defined as 𝑣=(𝑥1,𝑥2,𝑥3,,𝑥𝑛)𝑛 then the length or the magnitude of v is a scalar, that is:

|𝑣|=𝑣=𝑣𝑣=𝑥21+𝑥22++𝑥2𝑛

Angle between two vectors

The angle between two vectors is given as:

𝜃=cos1(𝑣1𝑣2|𝑣1||𝑣2|)

Linear combination of vectors

Consider a set 𝑆={𝑣1,𝑣2,,𝑣𝑛}, then a new vector 𝑣=𝛼1𝑣1+𝛼2𝑣2+,𝛼𝑛𝑣𝑛 is called a linear combination of 𝑣1,𝑣2,,𝑣𝑛 where 𝛼1,𝛼2,,𝛼𝑛 are scalars.
As an example, let’s try to create a linear combination from the given vectors.
ex.

𝑣1=(1,0,1)𝑣2=(0,2,1)𝑣3=(1,2,1)𝛼1𝑣1+𝛼2𝑣2+𝛼3𝑣3=𝛼1(1,0,1)+𝛼2(0,2,1)+𝛼3(1,2,1)=(𝛼1+𝛼3,2𝛼2+2𝛼3,(𝛼1+𝛼2+𝛼3))

Linearly dependent and independent vectors

A set of vectors 𝑆={𝑣1,𝑣2,,𝑣𝑛} is linearly independent if the vector equation

𝛼1𝑣1+𝛼2𝑣2+𝛼3𝑣3++𝛼𝑛𝑣𝑛=0

which should hold only when

𝛼1=𝛼2=𝛼3==𝛼𝑛=0

if not, 𝑆 is linearly dependent and the vectors in 𝑆 have a linear relationship between them.

ex, in 2

𝑆={(1,0),(1,1)}𝛼1(1,0)+𝛼2(1,1)=(0,0)here,𝛼2=0and𝛼1+𝛼2=0thus both are 0 and S contains linearly independent vectors

another ex. in 3

𝑆={(1,1,0),(1,0,1),(0,1,1)}𝛼1(1,1,0)+𝛼2(1,0,1)+𝛼3(0,1,1)=(0,0,0)𝛼1+𝛼2=0𝛼1+𝛼3=0𝛼2+𝛼3=0thus𝛼3=𝛼1and𝛼1+𝛼2=0take𝛼1=2,𝛼2=2,𝛼3=2;then2(1,1,0)+(2)(1,0,1)+2(0,1,1)=(0,0,0)which holds even when𝛼1,𝛼2,𝛼3are non-zeroThus S contains linearly dependent vectors
  • In 𝑛 a set of more than 𝑛 vectors is linearly dependent.
  • Any set of vectors containing the zero vector is linearly dependent.

Orthogonal vectors

We say that a set of vectors 𝑣1,𝑣2,,𝑣𝑛 are mutually (pairwise) orthogonal if 𝑣𝑖𝑣𝑗=0 for 𝑖𝑗 (dot product is zero).
ex. in 3
{(1,0,1),(1,2,1),(1,2,1)} is a set of vectors, and

(1,0,1)(1,2,1)=0(1,0,1)(1,2,1)=0(1,2,1)(1,2,1)=0

thus they are orthogonal.

Orthonormal vectors

A set of orthogonal vectors is orthonormal if each vector has length 1.

  • a set of orthogonal vectors is linearly independent.

Feature vectors in machine learning

Recall that features are nothing but the predictors or attributes of a data set.
some basic vector operations using numpy

import numpy as np
 
v_1 = np.array([1, -1, 2])
v_2 = np.array([2, 4, 8])
 
# sum of the vectors
print(v_1 + v_2)
 
# length of v_1
print(np.linalg.norm(v_1))
 
# dot product
print(np.dot(v_1, v_2))