[Numpy-svn] r2964 - in trunk/numpy: core core/tests lib linalg

numpy-svn at scipy.org numpy-svn at scipy.org
Sat Aug 5 02:48:54 CDT 2006


Author: oliphant
Date: 2006-08-05 02:48:48 -0500 (Sat, 05 Aug 2006)
New Revision: 2964

Modified:
   trunk/numpy/core/fromnumeric.py
   trunk/numpy/core/ma.py
   trunk/numpy/core/tests/test_ma.py
   trunk/numpy/lib/convertnumericA.py
   trunk/numpy/lib/function_base.py
   trunk/numpy/lib/polynomial.py
   trunk/numpy/linalg/linalg.py
Log:
Fix uses of nonzero and add flatnonzero

Modified: trunk/numpy/core/fromnumeric.py
===================================================================
--- trunk/numpy/core/fromnumeric.py	2006-08-05 07:01:54 UTC (rev 2963)
+++ trunk/numpy/core/fromnumeric.py	2006-08-05 07:48:48 UTC (rev 2964)
@@ -230,8 +230,7 @@
     return a.ravel(order)
 
 def nonzero(a):
-    """nonzero(a) returns the indices of the elements of a which are not zero,
-    a must be 1d
+    """nonzero(a) returns the indices of the elements of a which are not zero
     """
     try:
         nonzero = a.nonzero
@@ -241,7 +240,6 @@
         res = nonzero()
     return res
     
-
 def shape(a):
     """shape(a) returns the shape of a (as a function call which
        also works on nested sequences).

Modified: trunk/numpy/core/ma.py
===================================================================
--- trunk/numpy/core/ma.py	2006-08-05 07:01:54 UTC (rev 2963)
+++ trunk/numpy/core/ma.py	2006-08-05 07:48:48 UTC (rev 2964)
@@ -445,9 +445,8 @@
 negative = masked_unary_operation(umath.negative)
 
 def nonzero(a):
-    """returns the indices of the elements of a which are not zero and not masked
-
-    a must be 1d
+    """returns the indices of the elements of a which are not zero
+    and not masked
     """
     return asarray(filled(a, 0).nonzero())
 

Modified: trunk/numpy/core/tests/test_ma.py
===================================================================
--- trunk/numpy/core/tests/test_ma.py	2006-08-05 07:01:54 UTC (rev 2963)
+++ trunk/numpy/core/tests/test_ma.py	2006-08-05 07:48:48 UTC (rev 2964)
@@ -306,7 +306,7 @@
     def check_testMaPut(self):
         (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d
         m = [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1]
-        i = numpy.nonzero(m)
+        i = numpy.nonzero(m)[0]
         putmask(xm, m, z)
         assert take(xm, i) == z
         put(ym, i, zm)

Modified: trunk/numpy/lib/convertnumericA.py
===================================================================
--- trunk/numpy/lib/convertnumericA.py	2006-08-05 07:01:54 UTC (rev 2963)
+++ trunk/numpy/lib/convertnumericA.py	2006-08-05 07:48:48 UTC (rev 2964)
@@ -13,6 +13,9 @@
  * Converts .flat to .ravel() except for .flat = xxx or .flat[xxx]
  * Replace xxx.spacesaver() with True
  * Convert xx.savespace(?) to pass + ## xx.savespace(?)
+
+ * Converts uses of 'b' to 'B' in the typecode-position of
+   functions and methods
 """
 __all__ = ['fromfile', 'fromstr']
 

Modified: trunk/numpy/lib/function_base.py
===================================================================
--- trunk/numpy/lib/function_base.py	2006-08-05 07:01:54 UTC (rev 2963)
+++ trunk/numpy/lib/function_base.py	2006-08-05 07:48:48 UTC (rev 2964)
@@ -7,7 +7,8 @@
            'nanargmin', 'nanmin', 'vectorize', 'asarray_chkfinite', 'average',
            'histogram', 'bincount', 'digitize', 'cov', 'corrcoef', 'msort',
            'median', 'sinc', 'hamming', 'hanning', 'bartlett', 'blackman',
-           'kaiser', 'trapz', 'i0', 'add_newdoc', 'add_docstring', 'meshgrid'
+           'kaiser', 'trapz', 'i0', 'add_newdoc', 'add_docstring', 'meshgrid',
+           'flatnonzero'
            ]
 
 import types
@@ -530,7 +531,7 @@
 
     Equivalent to compress(ravel(condition), ravel(arr)).
     """
-    return _nx.take(ravel(arr), nonzero(ravel(condition)))
+    return _nx.take(ravel(arr), nonzero(ravel(condition))[0])
 
 def insert(arr, mask, vals):
     """Similar to putmask arr[mask] = vals but the 1D array vals has the
@@ -997,3 +998,11 @@
     y = y.reshape(numRows,1)
     Y = y.repeat(numCols, axis=1)
     return X, Y
+
+def flatnonzero(a):
+    """Return indicies that are not-zero in flattened version of a
+
+    Equivalent to a.ravel().nonzero()[0]
+    """
+    return a.ravel().nonzero()[0]
+    

Modified: trunk/numpy/lib/polynomial.py
===================================================================
--- trunk/numpy/lib/polynomial.py	2006-08-05 07:01:54 UTC (rev 2963)
+++ trunk/numpy/lib/polynomial.py	2006-08-05 07:48:48 UTC (rev 2964)
@@ -90,7 +90,7 @@
         raise ValueError,"Input must be a rank-1 array."
 
     # find non-zero array entries
-    non_zero = NX.nonzero(NX.ravel(p))
+    non_zero = NX.nonzero(NX.ravel(p))[0]
 
     # find the number of trailing zeros -- this is the number of roots at 0.
     trailing_zeros = len(p) - non_zero[-1] - 1

Modified: trunk/numpy/linalg/linalg.py
===================================================================
--- trunk/numpy/linalg/linalg.py	2006-08-05 07:01:54 UTC (rev 2963)
+++ trunk/numpy/linalg/linalg.py	2006-08-05 07:48:48 UTC (rev 2964)
@@ -313,7 +313,7 @@
         else:
             w = wr+1j*wi
             v = array(vr, w.dtype)
-            ind = nonzero(wi != 0.0)        # indices of complex e-vals
+            ind = nonzero(wi != 0.0)[0]      # indices of complex e-vals
             for i in range(len(ind)/2):
                 v[ind[2*i]] = vr[ind[2*i]] + 1j*vr[ind[2*i+1]]
                 v[ind[2*i+1]] = vr[ind[2*i]] - 1j*vr[ind[2*i+1]]



More information about the Numpy-svn mailing list