Velocity Reviews > Extending Scientific.Statistics.Histogram...

# Extending Scientific.Statistics.Histogram...

bleh
Guest
Posts: n/a

 11-11-2003
....to include a removeData(datatoremove) function, to mirror the
where this has been done already, if you could point me in that
direction I'd be much obliged...

TIA

bleh
Guest
Posts: n/a

 11-12-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) (bleh) wrote in message news:<(E-Mail Removed). com>...
> ...to include a removeData(datatoremove) function, to mirror the
> where this has been done already, if you could point me in that
> direction I'd be much obliged...
>
> TIA

NM -- I figured out the (embarrassingly, ridiculously easy) solution
on my own. Here it is, in case anybody wants it...

import Numeric; N = Numeric
from Scientific.Statistics.Histogram import Histogram

class ExtendedHistogram(Histogram):
def __init__(self, data, nbins, range=None):
Histogram.__init__(self, data, nbins, range)
self._setup(data, nbins, range)

def removeData(self, data):
"""
Remove the values in |data| (a sequence of numbers) from the
originally supplied data. Note that this does not affect the
default range of the histogram, which is fixed when the
histogram is created.
"""
n = (len(data)+999)/1000
for i in range(n):
self._removeData(data[1000*i:1000*(i+1)])

def _removeData(self, data):
data = N.array(data, N.Float)
data = N.repeat(data, N.logical_and(N.less_equal(data, self.max),
N.greater_equal(data, self.min)))
data = N.floor((data - self.min)/self.bin_width).astype(N.Int)
nbins = self.array.shape[0]
data), -1)
histo[-1] = histo[-1] + N.add.reduce(N.equal(nbins, data))
# this next line is the only change... changed the "+" to a "-"
self.array[:, 1] = self.array[:, 1] - histo