Parameter Update Step

~10 mincode completion

Implement gradient_step(weights, gradient, learning_rate) that returns the updated weights after one gradient descent step.

Examples

Standard update reduces weights

Input
gradient_step([1, 2], [0.5, -1], 0.1)
Output
[0.95, 2.1]

All-zero gradient: weights unchanged

Input
gradient_step([5, 5], [0, 0], 0.5)
Output
[5, 5]

Large learning rate scales gradient

Input
gradient_step([0, 0, 0], [1, 2, 3], 0.01)
Output
[-0.01, -0.02, -0.03]

Hints

Hint 1

Work directly with the arguments weights, , learning_rate and return the result rather than printing it.

Hint 2

A common slip here: added gradient instead of subtracting.

Requirements

  • weights: Current parameter vector

  • : Gradient of the loss w.r.t. weights

  • learning_rate: Step size (alpha)

  • Return Updated weight vector.

Constraints

  • Allowed library: NumPy only

  • Time limit: 200 ms, Memory: 64 MB

Where this shows up

~10 min

3 employers weight this skill

1 big tech firm, 1 frontier lab, 1 quant fund. Top match scores 80.

Python
import numpy as np

def gradient_step(weights: np.ndarray, gradient: np.ndarray, learning_rate: float) -> np.ndarray:
    """
    Perform one gradient descent update.

    Args:
        weights:       Current parameter vector
        gradient:      Gradient of the loss w.r.t. weights
        learning_rate: Step size (alpha)

    Returns:
        Updated weight vector.
    """
    # YOUR CODE HERE
    pass
Loading docs…

The AI Mentor needs an account

It reads your code and the failing tests and nudges you toward the fix without handing you the answer. Free accounts get it on every problem you're working on today.