TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Sample Variance & Standard Deviation

Probability and Statistics
Easy

Compute unbiased sample variance using Bessel's 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

Then compute sample standard deviation:

s=s2s = \sqrt{s^2}s=s2​

Here, nnn is the sample count, xix_ixi​ is one observation, and xˉ\bar{x}xˉ is the sample mean. Return variance and standard_deviation in a dictionary of Python floats.

Loading visualization...

Examples

Input: x = [1, 2, 3]

Output: {"variance": 1.0, "standard_deviation": 1.0}

Explanation: The squared deviations from the mean sum to 2, and dividing by n minus 1 gives 1.

Input: x = [5, 7]

Output: {"variance": 2.0, "standard_deviation": 1.414214}

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

Output: {"variance": 0.0, "standard_deviation": 0.0}

Hint 1

Compute centered = x - np.mean(x).

Hint 2

Divide np.sum(centered ** 2) by x.size - 1, then take its square root.

Requirements

  • Center every observation by the sample mean
  • Divide the squared-deviation sum by n minus 1
  • Return exactly variance and standard_deviation in a dictionary of Python floats

Constraints

  • x is a one-dimensional numeric list with at least two values
  • Use NumPy only
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 using Bessel's 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

Then compute sample standard deviation:

s=s2s = \sqrt{s^2}s=s2​

Here, nnn is the sample count, xix_ixi​ is one observation, and xˉ\bar{x}xˉ is the sample mean. Return variance and standard_deviation in a dictionary of Python floats.

Loading visualization...

Examples

Input: x = [1, 2, 3]

Output: {"variance": 1.0, "standard_deviation": 1.0}

Explanation: The squared deviations from the mean sum to 2, and dividing by n minus 1 gives 1.

Input: x = [5, 7]

Output: {"variance": 2.0, "standard_deviation": 1.414214}

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

Output: {"variance": 0.0, "standard_deviation": 0.0}

Hint 1

Compute centered = x - np.mean(x).

Hint 2

Divide np.sum(centered ** 2) by x.size - 1, then take its square root.

Requirements

  • Center every observation by the sample mean
  • Divide the squared-deviation sum by n minus 1
  • Return exactly variance and standard_deviation in a dictionary of Python floats

Constraints

  • x is a one-dimensional numeric list with at least two values
  • Use NumPy only
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.