Extending Scientific.Statistics.Histogram...

B

bleh

....to include a removeData(datatoremove) function, to mirror the
existing addData(datatoadd) function. If anybody knows of somewhere
where this has been done already, if you could point me in that
direction I'd be much obliged...

TIA
 
B

bleh

...to include a removeData(datatoremove) function, to mirror the
existing addData(datatoadd) function. If anybody knows of somewhere
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)
self.addData(data)

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]
histo = N.add.reduce(N.equal(N.arange(nbins)[:,N.NewAxis],
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top