Skip to content

Instantly share code, notes, and snippets.

@Porter97
Last active November 26, 2016 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Porter97/1c542bdb3b47fce5202c9b29b85e98de to your computer and use it in GitHub Desktop.
Save Porter97/1c542bdb3b47fce5202c9b29b85e98de to your computer and use it in GitHub Desktop.
#sum
def x_sum(x_input):
x = 0
for each in x_input:
x += each
return x
#average
def x_average(x_input):
x = x_sum(x_input)/float(len(x_input))
return x
#variance
def x_variance(x_input):
num = len(x_input)
average = x_average(x_input)
variance = 0
for x in x_input:
variance += float(average - x) ** 2
return variance/num
#standard deviation
def x_std_deviation(variance):
return variance ** 0.5
variance = x_variance(x_input)
print x_std_deviation(variance)
print x_sum(x_input)
print x_average(x_input)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment