summaryrefslogtreecommitdiff
path: root/numpy/polynomial/chebyshev.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/polynomial/chebyshev.py')
-rw-r--r--numpy/polynomial/chebyshev.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/numpy/polynomial/chebyshev.py b/numpy/polynomial/chebyshev.py
index 00cac2527..4d87c8470 100644
--- a/numpy/polynomial/chebyshev.py
+++ b/numpy/polynomial/chebyshev.py
@@ -1742,8 +1742,14 @@ def chebfit(x, y, deg, rcond=None, full=False, w=None):
if rcond is None :
rcond = len(x)*np.finfo(x.dtype).eps
- # scale the design matrix and solve the least squares equation
- scl = np.sqrt((lhs*lhs).sum(1))
+ # Determine the norms of the design matrix columns.
+ if lhs.dtype.char in np.typecodes['Complex']:
+ scl = np.sqrt((np.square(lhs.real) + np.square(lhs.imag)).sum(1))
+ else:
+ scl = np.sqrt(np.square(lhs).sum(1))
+ scl[scl == 0] = 1
+
+ # Solve the least squares problem.
c, resids, rank, s = la.lstsq(lhs.T/scl, rhs.T, rcond)
c = (c.T/scl).T