TensorTonicTensorTonic
Problems
Study PlansProjectsInterviewPricingFeedback
Problems
Loading...
1 / 1

Sample Variance & Standard Deviation

Probability and Statistics
Easy

Compute unbiased sample variance and standard deviation using Bessel's correction.

Sample Variance (Bessel Correction):

s2=1n−1∑i=1n(xi−xˉ)2s^2 = \frac{1}{n - 1} \sum_{i=1}^{n} (x_i - \bar{x})^2s2=n−11​i=1∑n​(xi​−xˉ)2

Standard Deviation: s=s2s = \sqrt{s^2}s=s2​

Function Arguments

  • x: list or array - Numeric data (n ≥ 2)
Loading visualization...

Examples

Input: x=[1,2,3]

Output: var=1.0, std=1.0

Input: x=[5,7]

Output: var=2.0, std=1.414

Input: x=[4,4,4,4]

Output: var=0.0, std=0.0

Hint 1

Compute mean first: mean_x = np.mean(x).

Hint 2

Use np.sum((x - mean_x) ** 2) / (n - 1) for variance.

Hint 3

Standard deviation is np.sqrt(var).

Requirements

  • Return tuple: (var, std)
  • Both values: scalar floats
  • Use Bessel correction (divide by n-1)
  • Vectorized implementation

Constraints

  • n ≥ 2 (need at least 2 samples)
  • NumPy only; time limit: 300ms
Try Similar Problems
Mean Median ModePercentilesBootstrap MeanPearson CorrelationCovariance Matrix

Sign in to take notes on this problem

Case 1
Case 2
Case 3

Accepts: array

You must run your code first.
PrevNext

Sample Variance & Standard Deviation

Probability and Statistics
Easy

Compute unbiased sample variance and standard deviation using Bessel's correction.

Sample Variance (Bessel Correction):

s2=1n−1∑i=1n(xi−xˉ)2s^2 = \frac{1}{n - 1} \sum_{i=1}^{n} (x_i - \bar{x})^2s2=n−11​i=1∑n​(xi​−xˉ)2

Standard Deviation: s=s2s = \sqrt{s^2}s=s2​

Function Arguments

  • x: list or array - Numeric data (n ≥ 2)
Loading visualization...

Examples

Input: x=[1,2,3]

Output: var=1.0, std=1.0

Input: x=[5,7]

Output: var=2.0, std=1.414

Input: x=[4,4,4,4]

Output: var=0.0, std=0.0

Hint 1

Compute mean first: mean_x = np.mean(x).

Hint 2

Use np.sum((x - mean_x) ** 2) / (n - 1) for variance.

Hint 3

Standard deviation is np.sqrt(var).

Requirements

  • Return tuple: (var, std)
  • Both values: scalar floats
  • Use Bessel correction (divide by n-1)
  • Vectorized implementation

Constraints

  • n ≥ 2 (need at least 2 samples)
  • NumPy only; time limit: 300ms
Try Similar Problems
Mean Median ModePercentilesBootstrap MeanPearson CorrelationCovariance Matrix

Sign in to take notes on this problem

Case 1
Case 2
Case 3

Accepts: array

You must run your code first.