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)x - Input (scalar, list, or NumPy array)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
Use np.maximum(0, x) for element-wise maximum between 0 and input values.
Sign in to take notes on this problem
Accepts: any
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)x - Input (scalar, list, or NumPy array)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
Use np.maximum(0, x) for element-wise maximum between 0 and input values.
Sign in to take notes on this problem
Accepts: any