The First Gradient
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
- 1 to 8 elements
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More PyTorch problems
- The k LargestEasy
- A Moving AverageMedium
- Count the ParametersMedium
- Cross-EntropyMedium
- Fit a LineMedium
- How Often RightMedium
- In BatchesMedium
- Many OutputsMedium