diff options
Diffstat (limited to 'numpy/polynomial/legendre.py')
-rw-r--r-- | numpy/polynomial/legendre.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/numpy/polynomial/legendre.py b/numpy/polynomial/legendre.py index 8fd64985b..b76e678c2 100644 --- a/numpy/polynomial/legendre.py +++ b/numpy/polynomial/legendre.py @@ -314,10 +314,17 @@ def legfromroots(roots) : return np.ones(1) else : [roots] = pu.as_series([roots], trim=False) - prd = np.array([1], dtype=roots.dtype) - for r in roots: - prd = legsub(legmulx(prd), r*prd) - return prd + roots.sort() + n = len(roots) + p = [legline(-r, 1) for r in roots] + while n > 1: + m = n//2 + tmp = [legmul(p[i], p[i+m]) for i in range(m)] + if n%2: + tmp[0] = legmul(tmp[0], p[-1]) + p = tmp + n = m + return p[0] def legadd(c1, c2): |