From 8bb96b14de3e4a8da0bbb3c378f84f601e9e87e6 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 29 Oct 2010 15:19:31 -0400 Subject: [PATCH] Use numpy.ndarray.sum() vs. __builtin__.sum() to compute hist bin counts. It's much faster: $ time python -c 'import numpy; sum(numpy.arange(int(1e6)))' real 0m3.312s user 0m3.188s sys 0m0.118s $ time python -c 'import numpy; numpy.arange(int(1e6)).sum()' real 0m0.878s user 0m0.753s sys 0m0.122s --- pysawsim/histogram.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pysawsim/histogram.py b/pysawsim/histogram.py index 5b4480b..bb66c05 100644 --- a/pysawsim/histogram.py +++ b/pysawsim/histogram.py @@ -69,7 +69,7 @@ class Histogram (object): bin_is = numpy.floor((data - self.bin_edges[0])/bin_width) self.counts = [] for i in range(len(self.bin_edges)-1): - self.counts.append(sum(bin_is == i)) + self.counts.append(sum(bin_is == i).sum()) self.total = float(len(data)) # some data might be outside the bins self.mean = data.mean() self.std_dev = data.std() -- 2.26.2