[Numpy-svn] r3265 - trunk/numpy/lib

numpy-svn at scipy.org numpy-svn at scipy.org
Thu Oct 5 14:05:49 CDT 2006


Author: oliphant
Date: 2006-10-05 14:05:47 -0500 (Thu, 05 Oct 2006)
New Revision: 3265

Modified:
   trunk/numpy/lib/polynomial.py
Log:
Fix ticket #323 --- problem with roots all zeros and all zero coefficients.

Modified: trunk/numpy/lib/polynomial.py
===================================================================
--- trunk/numpy/lib/polynomial.py	2006-10-05 19:02:34 UTC (rev 3264)
+++ trunk/numpy/lib/polynomial.py	2006-10-05 19:05:47 UTC (rev 3265)
@@ -92,6 +92,10 @@
     # find non-zero array entries
     non_zero = NX.nonzero(NX.ravel(p))[0]
 
+    # Return an empty array if polynomial is all zeros
+    if len(non_zero) == 0:
+        return NX.array([])
+
     # find the number of trailing zeros -- this is the number of roots at 0.
     trailing_zeros = len(p) - non_zero[-1] - 1
 
@@ -109,7 +113,7 @@
         A[0, :] = -p[1:] / p[0]
         roots = _eigvals(A)
     else:
-        return NX.array([])
+        roots = NX.array([])
 
     # tack any zeros onto the back of the array
     roots = hstack((roots, NX.zeros(trailing_zeros, roots.dtype)))



More information about the Numpy-svn mailing list