# Python - Creating a variance function

#1

I am new to python coding and I am trying to make my own functions such as mean and standard deviation on my own as practice. However, I am having trouble making a function for finding variance. the formula being

variance = \frac{1}{N - 1} \sum_{i = 1}^{N} (x_i - \mu_x)^2

I am trying to only use numpy.array, numpy.mean and the range() function. Any suggestions???

#2

1 / (N - 1)

times

N Sigma i=1 f(x)

where

f(x) = (x - µ) ** 2  for each x[i]


?

As I understand from math studies some decades ago, N - 1 is for a sample as opposed to a population? Just so your intentions are clear.

This question deals only with dissemination of your formula.

Now if this is correctly disseminated then it means there is a problem with the formula presented in the OP; to wit:

I don’t know NumPy, but if that is the exponent operator, then it doesn’t belong between parameters. Mind, if there is some definition I am unaware of, you will forgive me.