Jim Hugunin hugunin@mit.edu
Mon, 12 Aug 1996 13:24:28 -0400

This is not quite optimal (O(N lg N) instead of O(N)), but it is
adequate for my needs:

def histogram(a, bins):
"""Calculates the histogram of the values in the 1d array a.
bins is an array of the edges of the bins, there is one less
bin than items in this array.  Items that lie exactly on a bin
edge have a 50/50 chance of appearing in either bin."""
	n = binarysearch(sort(a), bins)
	n = concatenate( [n, [len(a)]] )
	return n[1:]-n[:-1]

Something like this will wind up in the standard library.


MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org