ReLU Derivative

EasyMachine LearningMathArray

Description

Given an array of pre-activation values, return the derivative of ReLU at each value: 1 where the input is positive and 0 otherwise.

Examples

Input:[1,-1,0,2]
Output:[1,0,0,1]
Explanation:

ReLU has a slope of one wherever the input is positive and a slope of zero everywhere else, including at and below zero.

Input:[-5,5]
Output:[0,1]
Explanation:

ReLU has a slope of one wherever the input is positive and a slope of zero everywhere else, including at and below zero.

Input:[0]
Output:[0]
Explanation:

ReLU has a slope of one wherever the input is positive and a slope of zero everywhere else, including at and below zero.

Constraints

  • 1 ≤ length ≤ 10⁴

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.