Step Function
The Step Function is a simple activation function that converts a value into either 0 or 1 based on a threshold.
In simple words
The Step Function asks a simple question: Is the input greater than the threshold? If yes, it returns 1. Otherwise, it returns 0.
How Does the Step Function Work?
The simplest Step Function uses zero as the threshold.
if z > 0:
output = 1
else:
output = 0
So there are only two possible outputs:
Example 1 — Positive Input
Suppose the neuron calculates:
z = 3.2
The Step Function checks:
3.2 > 0
This is true, so the output is:
output = 1
Example 2 — Negative Input
Now suppose the neuron calculates:
z = -2.5
The Step Function checks:
-2.5 > 0
This is false, so the output is:
output = 0
What Happens When z Is Zero?
With the rule we are using:
if z > 0:
output = 1
else:
output = 0
When:
z = 0
The condition z > 0 is false.
Therefore:
output = 0
Step Function Examples
Think of It Like a Switch
The Step Function behaves like an on/off switch.
This is why the Step Function is easy to understand: it makes a simple binary decision.
Real-World Example — Pass or Fail
Imagine a model that decides whether a student passes an exam.
Suppose the model produces a score:
score = 0.8
We could define:
if score > 0.5:
pass = 1
else:
pass = 0
Since:
0.8 > 0.5
the model produces:
pass = 1
The Threshold Does Not Have to Be Zero
Zero is only the simplest example. We can choose a different threshold.
For example:
threshold = 0.5
if z > threshold:
output = 1
else:
output = 0
Now suppose:
z = 0.8
Compare the value with the threshold:
0.8 > 0.5
Therefore:
output = 1
Step Function With Python
We can write the Step Function as a Python function.
def step_function(z):
if z > 0:
return 1
else:
return 0
print(step_function(3.2))
print(step_function(-2.5))
print(step_function(0))
Output:
1
0
0
How the Python Code Works
This line creates the function:
def step_function(z):
The function expects one value called z.
Then Python checks:
if z > 0:
If that condition is true, Python executes:
return 1
Otherwise, it executes:
return 0
So:
step_function(4)
returns:
1
while:
step_function(-3)
returns:
0
How the Step Function Fits Into a Neuron
Remember the complete neuron calculation:
z = (x1 * w1) + (x2 * w2) + bias
output = step_function(z)
For example:
x1 = 2
x2 = 3
w1 = 0.5
w2 = 0.4
bias = 1
z = (x1 * w1) + (x2 * w2) + bias
output = step_function(z)
print(output)
First:
z = (2 × 0.5) + (3 × 0.4) + 1
z = 3.2
Then:
step_function(3.2)
Because `3.2 > 0`, the final output is:
1
The Main Problem With the Step Function
The Step Function gives only two outputs:
There is no gradual change between these values.
For example, these inputs:
0.01
0.5
0.9
10
would all produce:
1
as long as they are greater than zero.
This makes the Step Function useful for learning the basic idea, but it is not generally suitable for training modern neural networks because its hard threshold does not provide a useful gradient for gradient-based learning.
Step Function vs Sigmoid
We will study Sigmoid in detail later in this lesson.
The Big Picture
Inputs
↓
Weights
↓
Weighted Sum
↓
+ Bias
↓
z
↓
Step Function
↓
0 or 1
The Step Function turns the neuron's calculated value into a simple binary output.
What You Should Remember
The Step Function compares the neuron's input with a threshold. If the value is above the threshold, it returns 1. Otherwise, it returns 0. It is useful for understanding activation functions, but its hard 0/1 behavior makes it unsuitable for most modern neural-network training.
Check Your Understanding
What does the Step Function return?
In our basic version, it returns either 0 or 1.
What happens when z = 5?
The output is 1 because 5 is greater than 0.
What happens when z = -2?
The output is 0 because -2 is not greater than 0.
Why isn't Step Function commonly used for
training modern neural networks?
Its hard threshold does not provide a useful
gradient for gradient-based optimization.