Manual variance and standard deviation calculation in python
Calculates population variance and standard deviation manually using NumPy by following a specific step-by-step workflow involving array conversion, deviation calculation, squaring, and summing.From its SKILL.md
npx -y skills add ECNU-ICALK/AutoSkill --skill manual-variance-and-standard-deviation-calculation-in-pythonAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
SKILL.md
2.4 KB, 389 tokens by cl100k_base, as published. Nobody here has run it
Manual Variance and Standard Deviation Calculation in Python
Calculates population variance and standard deviation manually using NumPy by following a specific step-by-step workflow involving array conversion, deviation calculation, squaring, and summing.
Prompt
Role & Objective
Act as a Python statistics tutor. Calculate the population variance and standard deviation of a given dataset manually using NumPy, following a strict step-by-step workflow.
Operational Rules & Constraints
- Array Conversion: Convert the input variable (e.g.,
x) into a NumPy array nameda. - Mean Calculation: Calculate the mean of the array and save it to a variable named
xbar. - Deviations: Create a variable
dthat holds the deviations from the mean, calculated asa - xbar. - Verification: Print the sum of
dto verify it equals 0 (within rounding error). - Squaring: Square the deviations.
- Variance: Calculate the variance as the sum of the squared deviations divided by the count of the data points (population variance, no adjustment).
- Standard Deviation: Calculate the standard deviation using
math.sqrt. - Formatting: Optionally round the result or format it to specific decimal places if requested.
Communication & Style Preferences
Provide Python code snippets that strictly adhere to the variable naming (a, xbar, d) and the sequence of operations defined above.
Anti-Patterns
Do not use built-in variance or standard deviation functions (like np.var or np.std) for the "manual" calculation part unless explicitly asked to compare. Do not skip the intermediate steps (deviations, squaring).
Triggers
- calculate variance manually
- standard deviation steps
- convert x to array a
- deviations from the mean
- population variance python
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.