TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Implement ReLU Activation

Activation Functions
Easy

Apply the Rectified Linear Unit elementwise:

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

Here, xxx is each input value. Return the transformed values as a NumPy array with the same shape as the input.

Loading visualization...

Examples

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

Output: [0.0, 0.0, 0.0, 3.0]

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

Input: x = 5

Output: 5.0

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

Output: [[0.0, 2.0], [3.0, 0.0]]

Hint 1

Convert the input with np.asarray(x, dtype=float).

Hint 2

Use np.maximum(0.0, x) for the elementwise threshold.

Requirements

  • Apply ReLU elementwise
  • Preserve the input shape
  • Return a NumPy array of floating-point values

Constraints

  • x is a finite numeric scalar or nonempty numeric list
  • x contains at most 1,000,000 values
  • Use NumPy only
Try Similar Problems
Leaky ReluElu ActivationSigmoid NumpyGeluSoftmax Function

Sign in to take notes on this problem

Case 1
Case 2
Case 3

Accepts: any

You must run your code first.
PrevNext

Implement ReLU Activation

Activation Functions
Easy

Apply the Rectified Linear Unit elementwise:

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

Here, xxx is each input value. Return the transformed values as a NumPy array with the same shape as the input.

Loading visualization...

Examples

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

Output: [0.0, 0.0, 0.0, 3.0]

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

Input: x = 5

Output: 5.0

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

Output: [[0.0, 2.0], [3.0, 0.0]]

Hint 1

Convert the input with np.asarray(x, dtype=float).

Hint 2

Use np.maximum(0.0, x) for the elementwise threshold.

Requirements

  • Apply ReLU elementwise
  • Preserve the input shape
  • Return a NumPy array of floating-point values

Constraints

  • x is a finite numeric scalar or nonempty numeric list
  • x contains at most 1,000,000 values
  • Use NumPy only
Try Similar Problems
Leaky ReluElu ActivationSigmoid NumpyGeluSoftmax Function

Sign in to take notes on this problem

Case 1
Case 2
Case 3

Accepts: any

You must run your code first.