Difficulty: Easy Tags: Activation Functions, Autograd
Walmart's smart-shelf sensors report a raw weight-delta signal every time an item is picked up or placed back, and that signal is noisy in both directions: small negative jitters from shelf vibration, and clean positive spikes from genuine removals. Before this feeds the restock-trigger model, every value below zero must be clamped away. You are implementing the exact ReLU layer used in the sensor-ingestion pipeline, forward and backward.
f(x) = max(0, x) forward
f'(x) = 1 if x > 0 else 0 backward
Given a batch of raw readings x and, separately, an upstream gradient g from the next layer,
compute the forward activation and the backward gradient g * f'(x).
n
x_1 x_2 ... x_n
g_1 g_2 ... g_n
Two lines: the activated values, then the backward gradient, each space-separated to 6 decimal places.
1 <= n <= 10^5Input
5
-2.0 0.0 3.0 -0.5 1.5
1.0 1.0 1.0 1.0 1.0
Output
0.000000 0.000000 3.000000 0.000000 1.500000
0.000000 0.000000 1.000000 0.000000 1.000000
No results yet
Run your code to check it against the examples, or submit to run every test.