Problems
Loading...
Step 2 of 6
ReLU Activation
Easy

Implement the rectified linear unit used throughout AlexNet.

ReLU⁡(x)=max⁡(0,x).\operatorname{ReLU}(x)=\max(0,x).

Apply the function elementwise and return a float64 NumPy array with the same shape as x.

Loading visualization...

Examples

Input: x = [-2,-0.5,0,3]

Output: [0,0,0,3]

Explanation: Negative values become zero while nonnegative values are unchanged.

Input: x = [[-1,2],[3,-4]]

Output: [[0,2],[3,0]]

Input: x = [0,1,5]

Output: [0,1,5]

Hint 1

np.maximum can compare the whole array with zero elementwise.

Requirements

  • Replace every negative element with zero.
  • Keep zero and positive elements unchanged.
  • Return a new float64 NumPy array with the same shape as x.

Constraints

  • x is a nonempty float64 NumPy array of any rank.
  • Every input value is finite.