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
Imagine you have two lists of numbers. You want to combine them by adding corresponding numbers together. That's vector addition. Let's say we have vector and vector . Adding these vectors gives us another vector where each element is the sum of the corresponding elements. Note: The vectors must be of the same length to perform this addition.
So, = [1+4, 2+5, 3+6] = [5, 7, 9].
Consider two delivery trucks: Truck A and Truck B. Truck A delivers 1, 2, and 3 packages to three different locations respectively, while Truck B delivers 4, 5, and 6 packages to the same locations. By using vector addition, we can determine the total number of packages delivered to each location as follows: [1+4, 2+5, 3+6] = [5, 7, 9]. This means the total packages delivered to each location are 5, 7, and 9 respectively.
Vector Addition: Python Code
Here's how we can implement the vector addition in python:
Let's break down the code:
np.array([1, 2, 3])andnp.array([4, 5, 6])create numpy arrays forv1andv2.- The expression
v1 + v2performs element-wise addition, resulting in[5, 7, 9].
Scalar Multiplication: Introduction and Example
Now let's discuss scalar multiplication. Imagine you have a list of numbers and you want to multiply each number by a constant value (scalar). For example, if and the scalar is 3, then multiplying each element by 3 gives us .
Imagine you are running a business and you have a list of product prices that are expected to increase by a fixed percentage (e.g., 20%). If the current prices are [10, 20, 30] dollars and you want to apply a 20% increase, you would multiply each price by 1.2. The new prices would be dollars.
