BasicsStandard DeviationGoogleMetaJane Street
Problem
Implement sample_std(x) returning the sample standard deviation s=n−11∑i=1n(xi−xˉ)2 (ddof=1) as a Python float for an array of length >= 2.
Why It Matters: Standard deviation expresses spread in the same physical units as the data (dollars, milliseconds, meters) and drives z-scores and confidence intervals.
Function Signature
import numpy as np
def sample_std(x) -> float:
Sample Input & Output
Example 1: Standard Sample
Input:
x = [2.0, 4.0, 4.0, 4.0, 5.0, 5.0, 7.0, 9.0]
Expected Output:
2.13809
Explanation: Mean is 5.0, sum of squared deviations is 32.0, so s=32/7≈2.13809.
Example 2: Two-Element Sample
Input:
x = [10.0, 14.0]
Expected Output:
2.828427
Explanation: Deviations from mean 12.0 are ±2.0; s=(4+4)/1=8≈2.828427.
Constraints & Edge Cases
- Return unbiased sample standard deviation (
ddof=1) as a float. - Remember
np.stddefaults toddof=0—you MUST passddof=1for sample standard deviation. - Return a Python
float.
Constraints & Evaluation Criteria
- Return unbiased sample standard deviation (`ddof=1`) as a float.
Hints
Python 3⌘/Ctrl+Enter to Run · ⌘/Ctrl+Shift+Enter to Submit
Loading Code Editor...
+1 Hidden Submit Case
Input / Scenario
[10, 12, 14, 16]
Expected Output / Criteria
2.5820