Skip to main content

Command Palette

Search for a command to run...

๐Ÿ“ฆ Day 3: Vectors and Scalars โ€“ The DNA of Machine Learning Data

Updated
โ€ข3 min read
O

Hello there! I'm a passionate tech enthusiast with a diverse range of interests, including quantum computing, web development, ReactJS, Python, data science, JS, and machine learning. As a seasoned writer and developer, I enjoy sharing my knowledge and experiences with others through engaging and informative articles. Whether you're looking to explore the cutting-edge world of quantum computing or want to learn how to build robust web applications using the latest technologies, I've got you covered. Join me on this exciting journey of discovery, and let's learn together!

๐ŸŽฏ Why You Need to Understand This

At the heart of every machine learning model lies a simple truth: all your input data โ€” images, text, audio, or numbers โ€” is ultimately converted into vectors.

Whether itโ€™s a pixel intensity, a word embedding, or a stock price โ€” machine learning learns from vectors of numbers.

This blog will help you understand what scalars, vectors, and vector operations are, and how they power ML.

๐Ÿ“ What is a Scalar?

A scalar is just a single number. It can be:

  • An integer (e.g., 5)

  • A real number (e.g., 3.14)

  • A boolean (e.g., 1 or 0)

In ML, a scalar might represent:

  • A label (e.g., โ€œspamโ€ = 0, โ€œnot spamโ€ = 1)

  • A weight in a model (e.g., w=0.2)

๐Ÿงฎ What is a Vector?

A vector is an ordered list of numbers โ€” think of it as a 1D array or a point in space.

Example:

$$\mathbf{x} = \begin{bmatrix}2\\-1\\4\end{bmatrix}$$

This is a 3-dimensional vector.

In ML, each input sample (like an image or a user profile) is converted into a vector:

  • A 28ร—28 grayscale image โ†’ vector of size 784

  • A sentence โ†’ vector using word embeddings like Word2Vec or BERT


๐Ÿ”„ Basic Vector Operations

  1. Addition

$$\mathbf{a} + \mathbf{b} = \begin{bmatrix}1\\2\end{bmatrix} + \begin{bmatrix}3\\4\end{bmatrix} = \begin{bmatrix}4\\6\end{bmatrix}$$

  1. Scalar Multiplication

$$2\cdot \begin{bmatrix}1\\2\\3\end{bmatrix} = \begin{bmatrix}2\\4\\6\end{bmatrix}$$

  1. Dot Product

$$\mathbf{a} \cdot \mathbf{b} = \sum a_i b_i = a_1 b_1 + a_2 b_2 + \dots + a_n b_n$$

Dot product is crucial in:

  • Cosine similarity

  • Neural networks

  • Projections & attention mechanisms

๐Ÿง  Geometric Intuition

  • Magnitude (Length) of a vector:

$$\|\mathbf{v}\| = \sqrt{v_1^2 + v_2^2 + \dots + v_n^2}$$

  • Direction: Vectors also have an angle. ML algorithms like SVM and k-NN often consider angle/similarity.

๐Ÿ“Š Vectors in ML Context

ML ConceptVector Representation
ImageVector of pixel values
SentenceVector of word embeddings
User behaviorVector of preferences/actions
Neural network layerVector of activations/weights

๐Ÿ› ๏ธ Try It Out in Python

pythonCopy codeimport numpy as np

a = np.array([1, 2, 3])
b = np.array([4, 5, 6])

print("Addition:", a + b)
print("Dot Product:", np.dot(a, b))
print("Norm (Length):", np.linalg.norm(a))

โœ… Key Takeaways

  • Scalars are single values; vectors are ordered collections of numbers.

  • Vectors are how ML models understand and learn from data.

  • Mastering vector operations gives you an edge in optimization, embeddings, and neural networks.

Math Behind Machine Learning: 60 Days of Insight

Part 3 of 4

Explore the importance of mathematics in machine learning. This blog series covers essential concepts like linear algebra, calculus, probability, and optimization. Perfect for beginners or those refreshing their knowledge to master AI algorithms.

Up next

๐Ÿงฎ Day 4: Matrix Operations & Why They Power Machine Learning

๐Ÿš€ Why This Topic Matters In machine learning, especially deep learning, matrices are everywhere: Your dataset? A matrix. Neural network weights? Matrices. Image data? Matrix of pixels. Understanding matrix operations helps you see how data moves, tr...

More from this blog

Om Koli: Insights, Tutorials, and News on Quantum Computing, JavaScript, ReactJS, Data Science, and Python.

10 posts

Hello there! I'm a passionate tech enthusiast with a diverse range of interests, including quantum computing, web development, ReactJS, Python, data science, JS, and machine learning.