[Numpy-tickets] [NumPy] #323: roots(polynomial) drops zero roots if only one non-zero coeff in polynomial

NumPy numpy-tickets at scipy.net
Thu Oct 5 12:24:42 CDT 2006


#323: roots(polynomial) drops zero roots if only one non-zero coeff in polynomial
----------------------------+-----------------------------------------------
 Reporter:  RyanGutenkunst  |       Owner:  somebody   
     Type:  defect          |      Status:  new        
 Priority:  normal          |   Milestone:  1.0 Release
Component:  numpy.lib       |     Version:             
 Severity:  normal          |    Keywords:             
----------------------------+-----------------------------------------------
 roots(polynomial) drops zero roots if only one non-zero coeff in
 polynomial

 Example (roots of x^{2} == 0)
 >>> numpy.roots((1,0,0))
 array([], dtype=float64)

 Also, roots fails if all coeffs are 0

 >>> numpy.roots((0,0))
 Traceback (most recent call last):
   File "<stdin>", line 1, in ?
   File "/afs/msc.cornell.edu/home/jsethna/ryang/installed/lib/python2.4
 /site-packages/numpy/lib/polynomial.py", line 96, in roots
     trailing_zeros = len(p) - non_zero[-1] - 1
 IndexError: index out of bounds

 The attached patch fixes both issues. (For the all-zero polynomial, an
 empty array is returned. This is what matlab does.)

-- 
Ticket URL: <http://projects.scipy.org/scipy/numpy/ticket/323>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.


More information about the Numpy-tickets mailing list