Implement ReLU Activation
Implement ReLU Activation
Implement the ReLU (Rectified Linear Unit) activation function. ReLU outputs the input value if positive, and 0 otherwise.
ReLU Formula:
ReLU(x)=max(0,x)Function Arguments
x- Input (scalar, list, or NumPy array)
Examples
Input: [-2, -1, 0, 3]
Output: [0.0, 0.0, 0.0, 3.0]
Negative values become 0, positive values unchanged
Input: 5.0
Output: 5.0
Positive scalar is returned unchanged
Input: [[-1, 2], [3, -4]]
Output: [[0.0, 2.0], [3.0, 0.0]]
Works element-wise on multi-dimensional arrays
Hint 1
Use np.maximum(0, x) for element-wise maximum between 0 and input values.
Requirements
- Return result using NumPy (not Python lists)
- Handle scalar, list, and NumPy array inputs
- Fully vectorized (no explicit Python loops)
- Preserve input shape
Constraints
- Use NumPy only
- Time limit: 200ms; Memory ≤ 64MB
Try Similar Problems
Log in to take notes on this problem
Accepts: any
Implement ReLU Activation
Implement ReLU Activation
Implement the ReLU (Rectified Linear Unit) activation function. ReLU outputs the input value if positive, and 0 otherwise.
ReLU Formula:
ReLU(x)=max(0,x)Function Arguments
x- Input (scalar, list, or NumPy array)
Examples
Input: [-2, -1, 0, 3]
Output: [0.0, 0.0, 0.0, 3.0]
Negative values become 0, positive values unchanged
Input: 5.0
Output: 5.0
Positive scalar is returned unchanged
Input: [[-1, 2], [3, -4]]
Output: [[0.0, 2.0], [3.0, 0.0]]
Works element-wise on multi-dimensional arrays
Hint 1
Use np.maximum(0, x) for element-wise maximum between 0 and input values.
Requirements
- Return result using NumPy (not Python lists)
- Handle scalar, list, and NumPy array inputs
- Fully vectorized (no explicit Python loops)
- Preserve input shape
Constraints
- Use NumPy only
- Time limit: 200ms; Memory ≤ 64MB
Try Similar Problems
Log in to take notes on this problem
Accepts: any