How to Scale a Vector (Scalar Multiplication Explained)

Scalar Multiplication (Scaling Vectors Explained)

We know how to add vectors together. But what happens if we just multiply a vector by a single number? This is called scalar multiplication, and a "scalar" is just the formal name for a regular number like 2, -1, or 0.5.

It’s one of the most fundamental operations in linear algebra. Watch the video for a quick visual walkthrough, then read on for the details.

The Intuition: Scaling an Arrow

Scalar multiplication is all about scaling or resizing a vector. Let's take our vector v = [2, 1]. Multiplying it by a scalar changes its magnitude, and sometimes its direction.

  • Multiplying by 2 makes the arrow twice as long, but keeps the same direction.
  • Multiplying by 0.5 makes it half as long.
  • Multiplying by -1 keeps the length but completely flips its direction by 180 degrees.

Visualizing how different scalars affect the vector [2, 1].

The Math & The Code

The math is exactly what you'd expect: you just multiply every element in the list by the scalar.

2 * [2, 1] = [2*2, 2*1] = [4, 2]

In NumPy, this is just as simple as using the standard multiplication operator.

import numpy as np

v = np.array([2, 1])
scalar = 2

# Simply use the '*' operator
scaled_v = scalar * v

print(scaled_v)
# Output: [4 2]

This is a core operation used everywhere in machine learning, especially for normalization, where you might scale a vector down to have a specific length, like 1.

Conclusion

Scalar multiplication is a simple but powerful tool for resizing vectors. By multiplying a vector by a single number, we can control its magnitude and direction, a fundamental step in preparing data for machine learning models.

Your Turn...

What do you think would happen if you added a vector to itself, like v + v? How would that relate to scalar multiplication? Share your thoughts in the comments!

This post is part of the "Decoding the Math of ML" series. For the previous part, check out: Vector Addition (Visually Explained).

Comments

Popular posts from this blog

Vector Addition (The Visual Guide for Developers)

What is a Vector? The True Building Blocks of Machine Learning

Retrieve list of Spooled files on System from SQL - IBM i