# Vector geometry

##### Linear Algebra

In this article, we will build some intuition about the geometry of vectors, their properties, and the operations on them.

## Prerequisites

To understand vectors, we recommend familiarity with the concepts in

Follow the above links to first get acquainted with the corresponding concepts.

## Vector: a geometric perspective

In the following interactive, we show a $2$-dimensional vector. The vector is an arrow, with the tail at the origin, and the head at the value of the vector. In this sense, the vector is an ordered tuple, such that the X-coordinate is the first coordinate of the vector and the Y-coordinate is the second.

A similar geometric interpretation can be imagined for an $n$-dimensional vector, in an $n$-dimensional space.

## Vector magnitude and direction

A vector has magnitude and direction. This should be intuitive from the geometric perspective you saw earlier.

The magnitude of a vector is measured in terms of its norm. The $p$-norm, for $p \ge 1$, provides a generalized way of computing any norm of a vector.

$$||\va||_p = \left( \sum_{i=1}^n |a_i|^p \right)^\frac{1}{p}$$

Three norms, derived from $p$-norm, are popular in machine learning.

• $L_1$ or Manhattan or Taxi-cab norm

$$||\va||_1 = \sum_{i=1}^n |a_i|$$

• $L_2$ or Euclidean norm

$$||\va||_2 = \left( \sum_{i=1}^n a_i^2 \right)^\frac{1}{2}$$

• $L_\infty$ or max norm

$$||\va||_\infty = \max_{i = 1}^n |a_i|$$

A vector with unit Euclidean norm, $|| \va ||_2 = 1$, is known as a unit vector.

Any vector can be normalized to a unit vector by dividing it with its norm, for example, the Euclidean norm.

$$\vec{\va} = \frac{\va}{||\va||_2}$$

$\vec{\va}$ has the same direction as that of the original vector, but has unit-magnitude.

## Vector norm: demo

Next, we present an interactive demonstration of vector norms.

Stretch and rotate the vector $\va$. Note the change in the various norms to build an intuition about vector magnitudes and direction. Also, use the slider to change the norm type to get a shape of the unit ball, the region that is traversed by the unit vector of a given norm type.

Understanding the shapes of these regions is crucial in choosing appropriate norm types in machine learning.

## Stretching or shrinking a vector

The magnitude of the vector can be stretched or shrunk. This is achieved by multiplication with a scalar.

$$\vb = \alpha \va$$

The result, $\vb$, is a vector with the same number of entries as $\va$. It is easy to prove that the magnitude of $\vb$ and that of $\va$ are related.

$$|| \vb ||_2 = |\alpha| || \va ||_2$$

Note that the scalar multiplication can also change direction.

• If $0 < \alpha < 1$, then $|| \vb ||_2 < || \va ||_2$. No change in direction.
• If $\alpha > 1$, then $|| \vb ||_2 > || \va ||_2$. No change in direction.
• If $-1 < \alpha < 0$, then $|| \vb ||_2 < || \va ||_2$. Also, $\vec{\vb}$ points in the opposite direction of $\vec{\va}$
• If $\alpha < -1$, then $|| \vb ||_2 > || \va ||_2$. Also, $\vec{\vb}$ points in the opposite direction of $\vec{\va}$

To build intuition about scalar multiplication, try out our interactive demo presented next. Vary the value of the scalar multiplier $c$ by adjusting the slider. Note the difference in the vector $\va$ while you do that.

## Vector stretching and shrinking: demo

Next, we present an interactive demonstration of scalar multiplication with a vector. Stretch and rotate the vector $\va$ by moving the arrowhead or change the scalar multiplier $c$ using the slider. Note the change in their product $c\va$.

Understanding these results intuitively is crucial to building a geometric perspective scalar multiplication of vectors.

## Rotating a vector

We saw that vectors have direction and that they can be shrunk, stretched, or flipped. In linear combination of vectors we will study how vectors can be rotated!

## Where to next?

Now that you understand vector geometry, it is time to build expertise in other topics in linear algebra.