Correlation
Return the correlation coefficient between the arrays x and y (the same length), as a float between -1 and 1. Hint: np.corrcoef(x, y) returns a 2 by 2 table; the number you want is off the diagonal.
Example 1
x [1,2,3]
y [2,4,6]
returns 1.0
y is exactly twice x, so they move together perfectly: 1.0.
Constraints
2 <= len(x) = len(y) <= 50- Neither array has all equal values
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More NumPy problems
- Count DistinctBeginner
- Count PositivesBeginner
- Count Target in GridBeginner
- Count the MaximumBeginner
- Cumulative MaxBeginner
- Day to Day ChangeBeginner
- Diagonal From ValuesBeginner
- Evenly SpacedBeginner