Linear Algebra Basics
Array Fundamentals
Working with multidimensional arrays
Our example dataset and basic plotting
ndarray methods
Array Axes
Vectorized Computing
Universal Functions (ufuncs)
Advanced array manipulation
Selected Topics in Mathematics and Statistics

Scalars and Vectors

Before starting with NumPy, we need to know and understand some basic linear algebra concepts. Perhaps these are well known to you. If so, I still recommend you still skim through this section.


Scalars are quantities that describe magnitudes. They have no dimensions. For example, real numbers are scalars. Physical examples of scalars are temperature, volume, and mass, among many others. Any function which returns a single number is called a scalar function.

In the spirit of generalization, we say that scalars have dimension zero.

NumPy treats scalars as Python does. Scalars in NumPy follow the four commutative operations we all know about:

  1. sum
  2. subtraction
  3. multiplication
  4. division


Vectors are ordered collections of one or more scalars with a variable number of elements. From here on, we will define a vector’s length as the number of elements in that vector.

As a data structure, vectors have one dimension, even if its length is m. This is because a single index can express the position of any element.

A visual representation of a vector

The list data structure in Python has similarities to a vector, but it is not the same as a mathematical vector. NumPy, on the other hand, does implement vectors in a mathematical sense. The only difference between NumPy vectors and mathematical vectors is that math vectors can be represented as rows or columns, while in NumPy, there is no distinction between the two representations.

In mathematics, vector operations such as sum and subtraction are done element-wise; however, the product between vectors is not as straightforward. Products using vectors may be very different from one another. Some examples are:

In the upcoming lessons, we will learn a lot more about vectors in NumPy and vector products.