"platforms/vscode:/vscode.git/clone" did not exist on "ea3c4747a80e09f51b5457f24e7dc8ce28e337ae"
Commit 8faeeb4d authored by Jason Swails's avatar Jason Swails
Browse files

More stable std calc.

parent 5c029ede
...@@ -495,15 +495,12 @@ class Quantity(object): ...@@ -495,15 +495,12 @@ class Quantity(object):
# Faster for numpy arrays # Faster for numpy arrays
std = self._value.std() std = self._value.std()
except AttributeError: except AttributeError:
sum1 = sum2 = 0.0 mean = self.mean()
for val in self._value: for val in self._value:
sum1 += val res = mean - val
sum2 += val * val var += res * res
nvals = len(self._value) var /= len(self._value)
sum1 /= nvals std = math.sqrt(var)
sum1 *= sum1
sum2 /= nvals
std = math.sqrt(abs(sum2 - sum1))
return Quantity(std, self.unit) return Quantity(std, self.unit)
def max(self): def max(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment