[Python-checkins] python/nondist/sandbox/statistics statistics.py, 1.1, 1.2

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Sun Feb 15 01:45:11 EST 2004


Update of /cvsroot/python/python/nondist/sandbox/statistics
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25075

Modified Files:
	statistics.py 
Log Message:
Add remaining docstrings.

Index: statistics.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/statistics/statistics.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** statistics.py	15 Feb 2004 06:03:57 -0000	1.1
--- statistics.py	15 Feb 2004 06:45:09 -0000	1.2
***************
*** 29,33 ****
  import bisect
  
! __all__ = ['mean', 'stddev', 'product', 'nlargest', 'nsmallest', 'select']
  
  def mean(data):
--- 29,34 ----
  import bisect
  
! __all__ = ['mean', 'median', 'nlargest', 'nsmallest',
!            'product', 'select', 'stddev']
  
  def mean(data):
***************
*** 89,94 ****
          return (s / k) ** 0.5           # population standard deviation
  
! def partition(iterable):
!     # Support routine for select
      under, notunder = [], []
      ua, nua = under.append, notunder.append
--- 90,101 ----
          return (s / k) ** 0.5           # population standard deviation
  
! def _partition(iterable):
!     """ Private function supporting select()
! 
!     Chooses the first element as pivot and returns tuple with a
!     list of values less than the pivot, the pivot itself, and a
!     a list of values not less than the pivot.
!     """
! 
      under, notunder = [], []
      ua, nua = under.append, notunder.append
***************
*** 106,112 ****
  
  def select(data, n):
!     'Find the nth rank ordered element'
      while 1:
!         p, pivot, q = partition(data)
          if n < len(p):
              data = p
--- 113,119 ----
  
  def select(data, n):
!     """Find the nth rank ordered element"""
      while 1:
!         p, pivot, q = _partition(data)
          if n < len(p):
              data = p
***************
*** 116,122 ****
              data = q
              n -= len(p) + 1
!         p = q = None
  
  def median(data):
      try:
          n = len(data)
--- 123,132 ----
              data = q
              n -= len(p) + 1
!         p = q = None    # Free unused partition
  
  def median(data):
+     """Find a value such that half of the data elements are above
+     the value and half are below.
+     """
      try:
          n = len(data)
***************
*** 131,139 ****
  
  def product(iterable):
!     "Compute the product of the data elements"
      return reduce(operator.mul, iterable, 1)
  
  def nlargest(iterable, n=1):            # XXX key= or cmp= argument
!     "Compute the n largest elements in the dataset"
      ## When collections.fibheap is available, use it instead of heapq
      it = iter(iterable)
--- 141,149 ----
  
  def product(iterable):
!     """Compute the product of the data elements"""
      return reduce(operator.mul, iterable, 1)
  
  def nlargest(iterable, n=1):            # XXX key= or cmp= argument
!     """Find the n largest elements in the dataset"""
      ## When collections.fibheap is available, use it instead of heapq
      it = iter(iterable)
***************
*** 150,154 ****
  
  def nsmallest(iterable, n=1):
!     "Compute the n largest elements in the dataset"
      ## When collections.fibheap is available, use it instead of bisect
      it = iter(iterable)
--- 160,164 ----
  
  def nsmallest(iterable, n=1):
!     """Find the n smallest elements in the dataset"""
      ## When collections.fibheap is available, use it instead of bisect
      it = iter(iterable)




More information about the Python-checkins mailing list