[Numpy-svn] r3108 - in trunk/numpy: . core

numpy-svn at scipy.org numpy-svn at scipy.org
Mon Sep 4 12:06:34 CDT 2006


Author: charris
Date: 2006-09-04 12:06:31 -0500 (Mon, 04 Sep 2006)
New Revision: 3108

Modified:
   trunk/numpy/add_newdocs.py
   trunk/numpy/core/fromnumeric.py
Log:
Add documentation to round and around to clear up confusion from numpy's choice
to round to even.


Modified: trunk/numpy/add_newdocs.py
===================================================================
--- trunk/numpy/add_newdocs.py	2006-09-03 19:01:47 UTC (rev 3107)
+++ trunk/numpy/add_newdocs.py	2006-09-04 17:06:31 UTC (rev 3108)
@@ -848,8 +848,29 @@
 
 
 add_newdoc('numpy.core.multiarray', 'ndarray', ('round',
-    """a.round(decimals=0, out=None)
+    """a.round(decimals=0, out=None) -> out (a). Rounds to 'decimals' places.
 
+    Keyword arguments:
+        decimals -- number of decimals to round to (default 0). May be negative.
+        out -- existing array to use for output (default a).
+
+    Return:
+        Reference to out, where None specifies the original array a.
+
+    Round to the specified number of decimals. When 'decimals' is negative it
+    specifies the number of positions to the left of the decimal point. The real
+    and imaginary parts of complex numbers are rounded separately. Nothing is
+    done if the array is not of float type.
+
+    The keyword 'out' may be used to specify a different array to hold the
+    result rather than the default 'a'. If the type of the array specified by
+    'out' differs from that of 'a', the result is cast to the new type.
+
+    Numpy rounds to even. Thus 1.5 and 2.5 round to 2, -0.5 and 0.5 round to 0,
+    etc. Results may also be surprising due to the inexact representation of
+    decimal fractions in IEEE floating point and the errors introduced in
+    scaling the numbers when 'decimals' is something other than 0.
+
     """))
 
 

Modified: trunk/numpy/core/fromnumeric.py
===================================================================
--- trunk/numpy/core/fromnumeric.py	2006-09-03 19:01:47 UTC (rev 3107)
+++ trunk/numpy/core/fromnumeric.py	2006-09-04 17:06:31 UTC (rev 3108)
@@ -546,11 +546,30 @@
             return asarray(a).shape[axis]
 
 def round_(a, decimals=0, out=None):
-    """Round 'a' to the given number of decimal places.  Rounding
-    behaviour is equivalent to Python.
+    """Returns reference to result. Copies a and rounds to 'decimals' places.
 
-    Return 'a' if the array is not floating point.  Round both the real
-    and imaginary parts separately if the array is complex.
+    Keyword arguments:
+        decimals -- number of decimals to round to (default 0). May be negative.
+        out -- existing array to use for output (default copy of a).
+
+    Return:
+        Reference to out, where None specifies a copy of the original array a.
+
+    Round to the specified number of decimals. When 'decimals' is negative it
+    specifies the number of positions to the left of the decimal point. The real
+    and imaginary parts of complex numbers are rounded separately. Nothing is
+    done if the array is not of float type.
+
+    The keyword 'out' may be used to specify a different array to hold the
+    result rather than the default copy of 'a'. If the type of the array
+    specified by 'out' differs from that of 'a', the result is cast to the new
+    type.
+
+    Numpy rounds to even. Thus 1.5 and 2.5 round to 2, -0.5 and 0.5 round to 0,
+    etc. Results may also be surprising due to the inexact representation of
+    decimal fractions in IEEE floating point and the errors introduced in
+    scaling the numbers when 'decimals' is something other than 0.
+
     """
     try:
         round = a.round



More information about the Numpy-svn mailing list