Trend Slope
Treat values[i] as the height of a point at x = i. Return the slope of the best-fit straight line through all the points, as a float. Hint: np.polyfit(x, values, 1) returns the slope first.
Example 1
values [1,3,5,7]
returns 2.0
The points lie exactly on a line that rises 2 per step.
Constraints
2 <= len(values) <= 50
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More NumPy problems
- Trimmed MeanEasy
- Vector DistanceEasy
- Weighted AverageEasy
- Weighted Row ScoresEasy
- Whole DollarsEasy
- Z-ScoresEasy
- Zero PositionsEasy
- Best Columns of Each RowMedium