Extending Scientific.Statistics.Histogram...

Discussion in 'Python' started by bleh, Nov 11, 2003.

  1. bleh

    bleh Guest

    ....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
    bleh, Nov 11, 2003
    #1
    1. Advertising

  2. bleh

    bleh Guest

    (bleh) wrote in message news:<>...
    > ...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
    bleh, Nov 12, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Oracle3001

    Building a Histogram using JAI

    Oracle3001, Oct 21, 2003, in forum: Java
    Replies:
    0
    Views:
    1,255
    Oracle3001
    Oct 21, 2003
  2. Jacky

    [Java Newbie] Histogram

    Jacky, Mar 2, 2005, in forum: Java
    Replies:
    2
    Views:
    606
  3. WreckingCru

    Word Histogram in C++??

    WreckingCru, Oct 16, 2003, in forum: C++
    Replies:
    7
    Views:
    2,921
    Alan Morgan
    Oct 23, 2003
  4. Engineer

    color histogram (help)

    Engineer, Mar 3, 2004, in forum: C++
    Replies:
    1
    Views:
    523
    Guybrush Threepwood
    Mar 3, 2004
  5. Andre

    Drawing a logarithmic histogram

    Andre, Jul 16, 2003, in forum: C Programming
    Replies:
    1
    Views:
    424
    Glen Herrmannsfeldt
    Jul 17, 2003
Loading...

Share This Page