๐Ÿ”ฅLimited Offer: Get 50% OFFon AI & Full Stack Courses๐Ÿ”ฅ
Back to Deep Learning Notes
Topic #24

Linear Transformations

A linear transformation is a function that maps vectors to vectors while preserving addition and scalar multiplication โ€” and every matrix multiplication you'll ever write, including every layer of a neural network before its activation function, is one.

Definition

\[ T(\mathbf{u}+\mathbf{v}) = T(\mathbf{u})+T(\mathbf{v}), \qquad T(c\mathbf{v}) = cT(\mathbf{v}) \]

Any function \(T\) satisfying both properties is a linear transformation, and every such transformation on finite-dimensional spaces can be represented as \(T(\mathbf{x}) = \mathbf{A}\mathbf{x}\) for some matrix \(\mathbf{A}\). This is why "matrix" and "linear transformation" are used almost interchangeably in this context.

Common Linear Transformations in 2-D

TransformationMatrix
Scale by factor \(k\)\(\begin{bmatrix}k & 0\\0 & k\end{bmatrix}\)
Rotate by angle \(\theta\)\(\begin{bmatrix}\cos\theta & -\sin\theta\\\sin\theta & \cos\theta\end{bmatrix}\)
Reflect across the x-axis\(\begin{bmatrix}1 & 0\\0 & -1\end{bmatrix}\)
Project onto the x-axis\(\begin{bmatrix}1 & 0\\0 & 0\end{bmatrix}\)

Visualizing a Transformation

Before: unit square T After: sheared & scaled

A linear transformation always maps the origin to itself and straight lines to straight lines โ€” it can rotate, scale, shear or reflect, but never curve or bend space.

Code โ€” Applying a Rotation

import numpy as np

theta = np.pi / 4   # 45 degrees
R = np.array([[np.cos(theta), -np.sin(theta)],
              [np.sin(theta),  np.cos(theta)]])

x = np.array([1, 0])
print(R @ x)   # approximately [0.707, 0.707] -- rotated 45 degrees counterclockwise

Why This Matters for Neural Networks โ€” The Motivation for Activation Functions

A neural network layer without an activation function, \(\mathbf{y} = \mathbf{W}\mathbf{x}+\mathbf{b}\), is an affine transformation (a linear transformation plus a shift). Stack two such layers and you get \(\mathbf{W}_2(\mathbf{W}_1\mathbf{x}+\mathbf{b}_1)+\mathbf{b}_2\), which algebraically simplifies to a single linear transformation with a new combined weight matrix and bias. No matter how many purely linear layers you stack, the whole network collapses to one linear function โ€” it can never learn a non-linear pattern. This is precisely why every layer in a real network is followed by a non-linear activation function (see the Activation Functions category next) โ€” without it, depth adds no representational power at all.

Common Mistakes

  • Assuming stacking more linear layers automatically increases a network's capacity โ€” without non-linear activations between them, it doesn't; the layers collapse into one.
  • Forgetting that a linear transformation always maps the zero vector to the zero vector โ€” a transformation that doesn't (e.g. one with a constant offset) is affine, not purely linear, even though deep learning code casually calls both "linear layers."

Interview Relevance

Q: "Why do neural networks need activation functions between layers?" Without them, any stack of linear (matrix multiplication) layers mathematically collapses into a single linear transformation, regardless of depth. Non-linear activation functions are what let a deep network represent non-linear functions โ€” they are the entire reason depth adds representational power.

Practice Question

Verify algebraically that stacking \(\mathbf{y} = \mathbf{W}_2(\mathbf{W}_1\mathbf{x})\) (no bias, no activation) is equivalent to a single linear transformation \(\mathbf{y}=\mathbf{W}'\mathbf{x}\). What is \(\mathbf{W}'\) in terms of \(\mathbf{W}_1\) and \(\mathbf{W}_2\)?

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

Linear Transformations โ€“ FAQs

Quick answers about learning Linear Transformations in Deep Learning.

This free note from CodingNow 2.0 explains Linear Transformations 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 Linear Transformations, is 100% free with no signup required.
With focused practice, most students grasp Linear Transformations 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