How to calculate a standard deviation array
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
Standard deviation is a statistical measure that quantifies the amount of variation or dispersion in a set of data values. It provides insight into how spread out the data points are from the mean (average) of the dataset. Understanding standard deviation is crucial in fields such as finance, research, and engineering since it helps in understanding the variability and reliability of data.
In this article, we will explore how to calculate standard deviation for an array, the mathematical underpinnings, and practical examples to clarify the process. Additionally, we will discuss how standard deviation can be applied in different scenarios.
Definition and Formula
The standard deviation is the square root of the variance. The variance itself is the average of the squared differences from the mean. The standard deviation is denoted by (sigma) for a population and for a sample.
Formula for Calculating Standard Deviation
For a population:
For a sample:
where: • is the number of data points in the population. • is the number of data points in the sample. • is each data point in the dataset. • is the mean of the population. • is the mean of the sample.
Step-by-Step Calculation
Example
Let's calculate the standard deviation for the following array of numbers considering it as a sample: [4, 8, 6, 5, 3].
- Calculate the Mean:
- Calculate Each Deviation from the Mean:• 4: • 8: • 6: • 5: • 3:
- Square Each Deviation:• • • • •
- Calculate the Variance:
- Calculate the Standard Deviation:
Summary Table
| Step | Description |
| Calculate Mean | Compute the average of the data |
| Find Deviations | Subtract the mean from each data point |
| Square Deviations | Square each deviation value |
| Calculate Variance | Find average of squared deviations |
| Calculate Standard Deviation | Take square root of the variance |
Considerations
• Population vs. Sample: Choose the right formula based on whether you have the entire population or a sample. The divisor in the variance formula differs ( for population, for sample, known as Bessel's correction). • Units: The units of standard deviation are the same as the dataset, unlike variance which is squared. • Outliers: Be cautious as extreme values can affect the standard deviation.
Applications
• Quality Control: In manufacturing, ensure product consistency. • Risk Assessment: In finance, measure investment risk. • Scientific Research: Assess experiment reliability and data precision.
Conclusion
Standard deviation is a fundamental statistical tool that aids in understanding the variability within a dataset. By following a structured approach to compute standard deviation, you can gain insights into the data's spread and make more informed decisions. Whether working with a full population or a sample, applying the correct formula ensures accurate analysis.
Related reading
- How to calculate distance between 2D matrices
- How to calculate Ebk of networks with Python?
- How to calculate GINI INDEX for binary classification?
- How to calculate logistic regression accuracy
- How to calculate an angle from three points?
- How to calculate or approximate the median of a list without storing the list
- how to calculate PDF in tensorflow
- How to Calculate R2 in Tensorflow

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.