Gradient Descent Step

MediumMachine LearningMath

Description

Given a weight vector, a gradient vector of the same length, and a learning rate, return the updated weights after one gradient-descent step: each weight minus the learning rate times its gradient. Round each result to 4 decimal places.

Examples

Input:[1,2,3], [0.1,0.2,0.3], 1
Output:[0.9,1.8,2.7]
Explanation:

Each weight moves against its gradient by a step proportional to the learning rate, nudging the model toward lower loss.

Input:[5,5], [1,1], 0.5
Output:[4.5,4.5]
Explanation:

Each weight moves against its gradient by a step proportional to the learning rate, nudging the model toward lower loss.

Input:[0,0], [2,-2], 0.1
Output:[-0.2,0.2]
Explanation:

Each weight moves against its gradient by a step proportional to the learning rate, nudging the model toward lower loss.

Constraints

  • 1 ≤ length ≤ 10⁴
  • learning rate > 0

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.