Blog

EN
Basic concepts of linear algebra

Basic concepts of linear algebra

4 min read

Series: Linear algebra for Machine Learning

2 parts

Algebra allows us to represent and manipulate real-world problems using numbers. Thanks to algebra, we can model relationships, analyze data, and find solutions in a logical and structured way.

I will be showing all examples in Python using the NumPy library.

First of all, we must import the library:

import numpy as np

Concepts

Theory might seem boring, but it is necessary to build the foundation we need to correctly handle practical topics.

What is a scalar?

These are quantities that only have magnitude. Simply put, it's just a number.

What is a vector?

It is an ordered list of scalars that describe an object.

Why ordered? Because the vector [2, 5] is not the same as [5, 2].

For example, we could represent the ratings a movie has in different genres:

# Action, Drama, Comedy
movie = np.array([2.4, 5.8, 8.7])

What is a matrix?

It is a two-dimensional set of numbers in a rectangular shape, organized in rows and columns.

In Machine Learning, rows represent observations and columns represent features.

movies = np.array([
    [8.5, 4.0, 6.5, 7.5],  # Movie A
    [5.0, 9.0, 6.0, 8.0],  # Movie B
    [9.0, 2.0, 7.0, 6.5]   # Movie C
])

What is a tensor?

These are mathematical objects that store numerical values and can have various dimensions.

For example, we can represent a pixel on our screen. First, you have to understand that a pixel is made up of three color values, where each one represents a channel (RGB).

image = np.array([
    [
        [255, 0, 0], # Red,
        [0, 255, 0], # Green
        [0, 0, 255] # Blue
    ],
])

# Graph
plt.imshow(image)
plt.title("Tensor Image")
plt.axis('off')
plt.show()

Example of Tensor pixel

Summary

  • The foundations of today's world rely heavily on linear algebra, especially in Artificial Intelligence.
  • NumPy and Matplotlib are fundamental tools that you must know how to use.
  • A scalar is a number.
  • A vector is an ordered list of scalars representing an object.
  • A matrix is a table of numbers, where rows are observations and columns are features.
  • A tensor is a mathematical object that stores numerical values and can have different dimensions (1D, 2D, 3D, 4D, etc.).

Share this article on