1
0
mirror of https://github.com/TREX-CoE/qmc-lttc.git synced 2024-10-14 20:12:12 +02:00
qmc-lttc/qmc_stats.py

18 lines
334 B
Python
Raw Normal View History

#!/usr/bin/env python3
2021-01-07 10:01:55 +01:00
from math import sqrt
def ave_error(arr):
M = len(arr)
2021-01-26 00:22:37 +01:00
assert(M>0)
2021-01-29 13:23:00 +01:00
2021-01-26 00:22:37 +01:00
if M == 1:
2021-01-29 13:23:00 +01:00
average = arr[0]
error = 0.
2021-01-26 00:22:37 +01:00
else:
average = sum(arr)/M
variance = 1./(M-1) * sum( [ (x - average)**2 for x in arr ] )
error = sqrt(variance/M)
2021-01-29 13:23:00 +01:00
return (average, error)