forked from TheAlgorithms/Python
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary_step.py
More file actions
Latest commit
36 lines (23 loc) · 858 Bytes
/
Copy pathbinary_step.py
File metadata and controls
36 lines (23 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
This script demonstrates the implementation of the Binary Step function.
It's an activation function in which the neuron is activated if the input is positive
or 0, else it is deactivated
It's a simple activation function which is mentioned in this wikipedia article:
https://en.wikipedia.org/wiki/Activation_function
"""
importnumpyasnp
defbinary_step(vector: np.ndarray) ->np.ndarray:
"""
Implements the binary step function
Parameters:
vector (ndarray): A vector that consists of numeric values
Returns:
vector (ndarray): Input vector after applying binary step function
>>> vector = np.array([-1.2, 0, 2, 1.45, -3.7, 0.3])
>>> binary_step(vector)
array([0, 1, 1, 1, 0, 1])
"""
returnnp.where(vector>=0, 1, 0)
if__name__=="__main__":
importdoctest
doctest.testmod()