Deep Learning from scratch - (1)

What if you could build a neural network using nothing but Python and a bit of math, no libraries, no magic, no black boxes? Today, most people learn deep learning using powerful frameworks like TensorFlow or PyTorch. These tools are incredibly useful and widely used in industry. But they come with a hidden cost: they abstract away how things actually work.
We can train a model in a few lines of code, but do you really understand what happens inside?
Why Learn Deep Learning from Scratch?
We define a model, call .fit(), and suddenly it starts making predictions. It works, but the internal mechanics remain unclear. Concepts like gradients, backpropagation, and loss functions often feel like things you just accept rather than understand.
When we implement each component ourself:
We can see how data flows through the network
We can understand how predictions are made
We can learn how errors are calculated
And most importantly, we can discover how the model learns
Instead of memorizing concepts, we can experience them.
It is enough to have a basic Python knowledge, comfortable with high school math, and curious about how deep learning really works. No need to know about deep learning frameworks.
Simple starting
Before we build a neural network, we need to understand the basic concepts that make it possible. Arrays and multidimensional data, basic operations using NumPy, Multivariable functions, Derivatives (the idea that makes learning possible). We won’t treat these as abstract math topics. Every concept will directly connect to how neural networks work.
A neural network is, at its core:
Numbers (data)
Organized in arrays
Passed through mathematical functions
Updated using derivatives
If you understand these four things, you understand the core of deep learning.
Arrays: The Language of Data
In deep learning, everything is a number, and numbers are stored in arrays.
print("Python list oprations: ")
a = [1,2,3]
b = [4,5,6]
print("a + b = ", a+b) # concatenation of lists
print("a * b = ", a*b) # this will raise an error because you cannot multiply two lists together
# Output:
# Python list oprations:
# a + b = [1, 2, 3, 4, 5, 6]
# Error
Lists are limited. For efficient computation, we use NumPy:
import numpy as np
print("Numpy array oprations: ")
a = np.array([1,2,3])
b = np.array([4,5,6])
print("a + b = ", a+b) # element-wise addition
print("a * b = ", a*b) # element-wise multiplication
# Output:
# Numpy array oprations:
# a + b = [5 7 9]
# a * b = [ 4 10 18]
Why NumPy?
Faster computations, Supports vector operations, Designed for numerical work
Multidimensional Arrays (Vectors & Matrices)
Neural networks don’t just use single lists, they use structured data.
Vectors (1D)
x = np.array([1, 2, 3])
Matrix (2D)
a = np.array([[1,2,3],
[4,5,6]])
print(a)
# Output:
# [[1 2 3]
# [4 5 6]]
Think of it like: Rows → data samples and Columns → features
Basic Operations (What Networks Actually Do)
Element-wise addition
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
print(a + b)
# Output: [5 7 9]
Scalar multiplication
print(a * 2)
# Output: [2 4 6]
Dot product (VERY important)
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
print(np.dot(a, b))
# Output: 32
Multivariable Functions
A neural network is just a function with many inputs.
def f(x, y):
return 2*x + 3*y
print(f(1, 2))
# Output: 8
Now imagine not 2 inputs, but 100 and not one function, but many layers. That’s a neural network.
Derivatives: How Learning Happens
A neural network learns by adjusting its parameters to reduce error. But how does it know which way to adjust? That’s where derivatives come in. The derivative tells us how the output changes when input changes.
def f(x):
return x**2
def derivative(x):
return 2*x
If:
x = 3 → derivative = 6
x = -3 → derivative = -6
This tells us which direction to move and how fast to move.
In neural networks, there are three steps to follow:
We make predictions
We calculate error
We use derivatives to reduce that error
This process is called learning. Without derivatives, neural networks cannot improve.
Arrays → store data
NumPy → performs fast computations
Multivariable functions → define models
Derivatives → enable learning
These are not separate topics. They are pieces of the same system.


