Covariance
MediumStatisticsMathArray
Description
Given two equal-length arrays x and y, return the population covariance (mean of the products of paired deviations from each mean), rounded to 4 decimal places.
Examples
Input:
x = [1,2,3], y = [4,5,6]Output:
0.6667Explanation:
Averaging the products of paired deviations from each mean gives 0.6667.
Input:
x = [1,2,3,4], y = [2,4,6,8]Output:
2.5Explanation:
Averaging the products of paired deviations from each mean gives 2.5.
Input:
x = [2,4,6], y = [6,4,2]Output:
-2.6667Explanation:
Averaging the products of paired deviations from each mean gives -2.6667.
Constraints
- •
1 ≤ x.length ≤ 10⁴ - •
x.length === y.length