Changeset 2976


Ignore:
Timestamp:
May 25, 2006, 5:22:58 PM (18 years ago)
Author:
ole
Message:

Option in histogram for frequency

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/utilities/numerical_tools.py

    r2972 r2976  
    204204
    205205
    206 def histogram(a, bins):
     206def histogram(a, bins, relative=False):
    207207    """Standard histogram straight from the Numeric manual
     208
     209    If relative is True, values will be normalised againts the total and
     210    thus represent frequencies rather than counts.
    208211    """
    209212
    210213    n = searchsorted(sort(a), bins)
    211214    n = concatenate( [n, [len(a)]] )
    212     return n[1:]-n[:-1]
     215
     216    hist = n[1:]-n[:-1]
     217
     218    if relative is True:
     219        hist = hist/float(sum(hist))
     220       
     221    return hist
    213222
    214223def create_bins(data, number_of_bins = None):
Note: See TracChangeset for help on using the changeset viewer.