diff options
author | endolith <endolith@gmail.com> | 2013-11-27 00:27:04 -0500 |
---|---|---|
committer | endolith <endolith@gmail.com> | 2015-01-25 00:50:08 -0500 |
commit | 1fc268723596266761f1124434676ac234248636 (patch) | |
tree | 7044618ffd26f4da74c40cd17d10db627bdfb29a /numpy/lib | |
parent | 7ce93ba046b1ff2fddd1f24090b21c01a7d6c25e (diff) | |
download | numpy-1fc268723596266761f1124434676ac234248636.tar.gz |
BUG: sort after conjugating so that poly() outputs real type for exact conjugates
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/polynomial.py | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/numpy/lib/polynomial.py b/numpy/lib/polynomial.py index de9376300..75f81b2a6 100644 --- a/numpy/lib/polynomial.py +++ b/numpy/lib/polynomial.py @@ -145,12 +145,11 @@ def poly(seq_of_zeros): if issubclass(a.dtype.type, NX.complexfloating): # if complex roots are all complex conjugates, the roots are real. roots = NX.asarray(seq_of_zeros, complex) - pos_roots = sort_complex(NX.compress(roots.imag > 0, roots)) - neg_roots = NX.conjugate(sort_complex( - NX.compress(roots.imag < 0, roots))) - if (len(pos_roots) == len(neg_roots) and - NX.alltrue(neg_roots == pos_roots)): - a = a.real.copy() + pos_roots = NX.compress(roots.imag > 0, roots) + neg_roots = NX.conjugate(NX.compress(roots.imag < 0, roots)) + if len(pos_roots) == len(neg_roots): + if NX.all(sort_complex(neg_roots) == sort_complex(pos_roots)): + a = a.real.copy() return a |