🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to Deep Learning Notes
Topic #12

Scalars, Vectors & Matrices

Every number a neural network ever touches — an input pixel, a weight, a whole layer's parameters — is stored as one of three basic mathematical objects: a scalar, a vector, or a matrix. Getting comfortable with these (and their notation) is the prerequisite for everything else in this hub.

The Three Objects

ObjectDimensionalityNotationExampleDL Analogy
Scalar0-D — a single numberItalic lowercase: \(a\)\(a = 5\)A learning rate, a single bias value
Vector1-D — an ordered list of numbersBold lowercase: \(\mathbf{x}\)\(\mathbf{x} = [1, 2, 3]\)A feature vector, a word embedding
Matrix2-D — a grid of numbers (rows × columns)Bold uppercase: \(\mathbf{W}\)\(\mathbf{W} = \begin{bmatrix}1 & 2\\3 & 4\end{bmatrix}\)A fully-connected layer's weights

Why This Matters Immediately

A single artificial neuron computes \(y = \mathbf{w}^\top \mathbf{x} + b\) — a vector \(\mathbf{x}\) (the inputs), a vector \(\mathbf{w}\) (the weights), and a scalar \(b\) (the bias). A full layer of neurons stacks many such weight vectors into a weight matrix \(\mathbf{W}\), so the whole layer becomes one matrix multiplication, \(\mathbf{y} = \mathbf{W}\mathbf{x} + \mathbf{b}\). Every note in the Neural Network Fundamentals category builds directly on this notation.

Shape — The Most Important Attribute

A vector of length \(n\) has shape \((n,)\). A matrix with \(m\) rows and \(n\) columns has shape \((m, n)\). In practice, the single most common bug in deep learning code is a shape mismatch — so get in the habit of writing down a tensor's shape every time you define one.

Code

import numpy as np

scalar = 5.0
vector = np.array([1.0, 2.0, 3.0])
matrix = np.array([[1.0, 2.0], [3.0, 4.0]])

print(scalar, type(scalar))
print(vector.shape)   # (3,)
print(matrix.shape)   # (2, 2)
import torch

scalar = torch.tensor(5.0)
vector = torch.tensor([1.0, 2.0, 3.0])
matrix = torch.tensor([[1.0, 2.0], [3.0, 4.0]])

print(scalar.shape, vector.shape, matrix.shape)
# torch.Size([]) torch.Size([3]) torch.Size([2, 2])

Common Mistakes

  • Confusing a vector of shape \((n,)\) with a matrix (column vector) of shape \((n, 1)\) — they behave differently under broadcasting and matrix multiplication (see Broadcasting).
  • Writing \(\mathbf{w}^\top \mathbf{x}\) as \(\mathbf{w} \mathbf{x}\) — the transpose is not optional notation, it's what makes the shapes align for a valid dot product.

Interview Relevance

Q: "What's the difference between a vector and a 1-D matrix?" Mathematically, a vector is typically treated as either a row or column matrix. In deep learning frameworks, a plain 1-D tensor of shape \((n,)\) is neither — it has no row/column orientation, which matters for how it broadcasts against a 2-D matrix. A shape of \((n,1)\) or \((1,n)\) is an explicit row/column matrix.

Practice Question

A dataset has 100 samples, each with 8 features. What is the shape of the matrix holding this dataset? What is the shape of a single sample's feature vector?

Want to go beyond the notes?

Join CodingNow 2.0's Deep Learning course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Scalars, Vectors & Matrices – FAQs

Quick answers about learning Scalars, Vectors & Matrices in Deep Learning.

This free note from CodingNow 2.0 explains Scalars, Vectors & Matrices in Deep Learning — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Deep Learning topic on CodingNow 2.0, including Scalars, Vectors & Matrices, is 100% free with no signup required.
With focused practice, most students grasp Scalars, Vectors & Matrices in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now