Skip to content
C

Activation Functions From Scratch

Easypython

Implement ReLU and Sigmoid from scratch (pure math, exactly as the notes' own conceptual relu() example does) and apply both to a list of numbers.

Why not build this in Keras/PyTorch? those frameworks are large, GPU-oriented libraries very unlikely to be available in a lightweight code-execution sandbox, and even training a tiny network introduces its own floating-point non-determinism across environments — but the activation functions THEMSELVES are just plain math (the notes' own relu() example already shows this), so this tests that underlying concept directly, dependency-free.

Approach: relu(x) is max(0, x); sigmoid(x) is 1 / (1 + e^-x) using math.exp. Apply both to every given number.

Input: One line: space-separated numbers.

Output: Two lines: the ReLU of each number as a list, then the Sigmoid of each number as a list (each value rounded to 4 decimal places).

Input (stdin)

Output

Run your code to see output here...