Basic Vector Operations

Lesson Introduction

Welcome! Today, we're diving into basic vector operations, which are foundational to your journey in machine learning. Understanding these operations will help you grasp more complex concepts later on. Our goals are to learn vector addition and scalar multiplication. We'll see why these operations are essential, learn how to implement them in Python, and understand their real-world applications.

Vector Addition: Introduction and Example

Vector Addition: Python Code

Here's how we can implement the vector addition in python:

Python
import numpy as np

# Vector addition using numpy
v1 = np.array([1, 2, 3])
v2 = np.array([4, 5, 6])

print("Vector Addition:", v1 + v2)  # Vector Addition: [5 7 9]

Let's break down the code:

  • np.array([1, 2, 3]) and np.array([4, 5, 6]) create numpy arrays for v1 and v2.
  • The expression v1 + v2 performs element-wise addition, resulting in [5, 7, 9].

Scalar Multiplication: Introduction and Example

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