Most of us may have probably learnt about vectors at school either in Geometry or Physics class (if you haven’t or happen to forget it, no problem! This post will start by explaining it again, as clear and simple as possible). One tricky thing when dealing with vectors is that they can be represented and interpreted in many different ways. Therefore, knowing what exactly it means in certain situation can really help to avoid the confusion.

First, let’s take a look at the basic again with the following vector definition in geometry:

A vector is a line with a direction.

That’s quite short, simple and easy to understand. To create a vector we can draw a straight line and then add the direction to it. One may say that the only difference between a vector and a line is the direction. A line doesn’t have/show/point to any direction. However, as soon as a direction is applied to it, then it becomes a vector. To aid imagination, you can think of a vector as an arrow in space.

The same but slightly more “erudite” definition could be:

A vector is an object or quantity with magnitude and direction.

I added “erudite” to the sentence because of the term *object*. Depending on where you see it (hopefully not in philosophy), the term *object* may have different meanings. For the sake of simplicity, let’s just say that an object is a thing in general. That thing could be anything depending on the context. For example: a line in geometry, a force in physics, etc. Because a force in physics (not in *Star Wars*) is a quantity that has magnitude and direction so using a vector is a perfect way to represent it.

In computer science, a vector is the same as a list of numbers (or an array), for example as in the Numpy library. In fact, the following definition can be found on Numpy official online documentation:

A

NumPy: the absolute basics for beginners (https://numpy.org/devdocs/user/absolute_beginners.html#numpy-the-absolute-basics-for-beginners)vectoris an array with a single dimension

It’s pretty common for software developers to think of an array as a list of numbers (or other objects) without direction. If so, why does Numpy still use an array as a vector when it doesn’t has any direction. Or… has it? If you feel confused, you’re not alone. However, before going into detail, here’s a quick example to create a vector in Numpy:

`a_vector = np.array([1, 2, 3, 4, 5, 6])`

To understand why, let’s go back and examine vectors in geometry. When a vector is viewed inside a coordinate system, whether it’s 2D or 3D or a higher dimension, the vector then can be represented as a list of coordinates within that system.

The following figure shows 4 vectors **u**, **w**, **a** and **b** in the Cartesian coordinate (or the XY-plane).

**Quick note:** Normally, an arrow bar is placed on top of a vector to denote that it’s a vector. Another way is to make it bold, such as: **u**, **v** and **w**.

Let’s take the vector **u** for example, this vector can be decomposed into two vectors **a**(3, 0) and **b**(0, 2) that sit on the x and y axes (or coordinates) accordingly. As the result of that, vector **u** can be simply represented using the array (3, 2). In fact, any vector has their tail placed at the origin 0(0, 0) can be decomposed into two vectors on x and y and be represented by an array in the exact same way.

For vector **u**, the catch here is that we first need to translate it so that its tail rests on the origin 0(0, 0). Only then we can use an array to represent it. A vector that starts at the origin is called a position vector. Note that it just happens for the figure above, the vector **u** is exactly the same as vector **w** after the translation but it doesn’t have to be.

Position vectors make our life a lot more easier because adding/subtracting two or more position vectors is done simply by adding/subtracting theirs corresponding coordinates and the resulting vector is also a position vector. The proof of this is quite easy and I encourage you to verify it.

So now you know why Numpy uses an array to represent a vector. How about the *single dimension* condition in the definition above? We actually don’t need to care about this one and safely skip it for now without negating our understanding about vector representation. Just for your information, the variable defined in following code snippet is not a vector because it has two dimension (not one), particularly it’s called a matrix in Numpy:

`a_matrix = np.array([[1, 2, 3], [4, 5, 6]])`

One last point worth mentioning is that: There’s a more complicated type of vectors whose elements can be functions (like polynomial functions), another vectors or maths objects. For example, (5 + 3x, (7, 2, 3)) is a valid vector in Linear Algebra. Such vector is often referenced in some more general abstract *vector space*. However, that goes beyond the scope of this post and if you’re curious enough you can learn more about this type of vectors in courses/books about Linear Algebra.

## Leave a Reply