在线等!求一个python程序:输入或读取一个任意大小的数组,输出这个数组的平均值和标准差!
2个回答
展开全部
import math
def avg(arr, n):
sum=0
for i in arr:
sum = sum+i
return (1.0*sum/n)
def standard_deviation(arr, n):
a=avg(arr,n)
value=0;
for i in arr:
value=value+(i-a)*(i-a)
return math.sqrt(1.0*value/n)
print "please input number first"
n=input()
print "please input data then"
arr=[]
for i in range(n):
data=input()
arr.append(data)
print "avg:",avg(arr,n)
print "standard deviation:",standard_deviation(arr,n)
展开全部
def function(inList):
import math
num = len(inList)
sum = 0
for e in inList:
sum = sum + e
average = sum/num
sqrtDiff = 0
for i in inList:
diff = i - average
sqrtAns = pow(diff,2)
sqrtDiff = sqrtAns + sqrtDiff
ans = sqrtDiff / num
answer = math.sqrt(ans)
return (average, answer)
import math
num = len(inList)
sum = 0
for e in inList:
sum = sum + e
average = sum/num
sqrtDiff = 0
for i in inList:
diff = i - average
sqrtAns = pow(diff,2)
sqrtDiff = sqrtAns + sqrtDiff
ans = sqrtDiff / num
answer = math.sqrt(ans)
return (average, answer)
追问
麻烦能不能写出主程序,能形成一个完整的程序。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询