FunctionRacerProblemsRace

The First Gradient

EasyPyTorchPython

Let y be the sum of x² + 3x over all the elements of x. Return the gradient of y with respect to x: for each element, how fast y changes when that element does. Let autograd work it out.

Example 1

x [1.0,2.0,-0.5]
returns [5.0,7.0,2.0]

The slope of x² + 3x is 2x + 3: at 1 that is 5, at 2 it is 7, at -0.5 it is 2.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More PyTorch problems