Browse Source

Don't divide by 0 when computing stddev if there is only 1 item in the set

Ian Goldberg 4 years ago
parent
commit
7a7e51b5f4
1 changed files with 6 additions and 3 deletions
  1. 6 3
      network.py

+ 6 - 3
network.py

@@ -120,9 +120,12 @@ class PerfStatsStats:
 
         def __str__(self):
             mean = self.tot/self.N
-            stddev = math.sqrt((self.totsq - self.tot*self.tot/self.N) \
-                    / (self.N - 1))
-            return "%f \pm %f" % (mean, stddev)
+            if self.N > 1:
+                stddev = math.sqrt((self.totsq - self.tot*self.tot/self.N) \
+                        / (self.N - 1))
+                return "%f \pm %f" % (mean, stddev)
+            else:
+                return "%f" % mean
 
     def __init__(self, usebw=False):
         self.usebw = usebw