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

๐ฏ 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
- Addition
$$\mathbf{a} + \mathbf{b} = \begin{bmatrix}1\\2\end{bmatrix} + \begin{bmatrix}3\\4\end{bmatrix} = \begin{bmatrix}4\\6\end{bmatrix}$$
- Scalar Multiplication
$$2\cdot \begin{bmatrix}1\\2\\3\end{bmatrix} = \begin{bmatrix}2\\4\\6\end{bmatrix}$$
- 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 Concept Vector Representation Image Vector of pixel values Sentence Vector of word embeddings User behavior Vector of preferences/actions Neural network layer Vector 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.
Subscribe to my newsletter
Read articles from Om Koli directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Om Koli
Om Koli
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!