Leaky ReLU Activation Function

Neural Units & Activations DS practice problem on Onlearn.

Difficulty: easy.

Topics: Understanding Leaky ReLU Activation Function, Leaky ReLU, Non-linearity, Dying ReLU Problem, Hyperparameter Tuning, Conditional Logic, Deep Learning Foundations, Numerical Computing, Mathematical Analysis, Software Engineering, Computational Complexity, Neural Units & Activations, Floating Point Arithmetic, Function Approximation, Algorithm Implementation, Gradient-Based Optimization.

Write a Python function leaky relu that implements the Leaky Rectified Linear Unit (Leaky ReLU) activation function. The function should take a float z as input and an optional float alpha, with a default value of 0.01, as the slope for negative inputs. The function should return the value after applying the Leaky ReLU function.