Basics of Vectors and Matrices

Lesson Introduction

Welcome to this exciting course path! This path focuses on teaching math concepts that are important for machine learning. Note that this path assumes that you have basic knowledge of the python programming language. You can use our Introduction Programming in Python course path to gain or solidify this knowledge.

Welcome to our lesson on the basics of vectors and matrices!

In this lesson, we'll explore what vectors and matrices are, why they're important in machine learning, and how to create and work with them in Python. By the end of this lesson, you'll understand how to define, display, and interpret vectors and matrices. Let's get started!

Concept: Vector

Creating and Displaying a Row Vector in Python

Let's see how we can create a row vector in Python using np.array() from the NumPy library. NumPy provides advanced linear algebra features that will be useful in the upcoming units of our course.

Python
import numpy as np

# Create a row vector
vector = np.array([1, 2, 3])

# Display the vector
print("Vector:", vector)  # Output: Vector: [1 2 3]

This shows a simple row vector with three numbers.

Creating and Displaying a Column Vector in Python

And this is how we represent the column vector using np.array():

import numpy as np

# Create a column vector
vector = np.array([
    [1],
    [2],
    [3]
])

# Display the vector
print("Vector:", vector)  # Output: Vector: [[1] [2] [3]]

Using np.array(), we specify a 2-dimensional structure for the column vector, but with one item in each row.

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal