diff options
author | Mike Taves <mwtoews@gmail.com> | 2021-08-30 11:01:34 +1200 |
---|---|---|
committer | Mike Taves <mwtoews@gmail.com> | 2021-09-01 21:50:59 +1200 |
commit | 64f15a94708095bf9d29af5dbfcc4b654a57248a (patch) | |
tree | 77bd3bf8a4f38561fee95fcfa3ea9e5247e6500b /numpy/lib/polynomial.py | |
parent | 5ae53e93b2be9ccf47bf72a85d71ea15d15a2eed (diff) | |
download | numpy-64f15a94708095bf9d29af5dbfcc4b654a57248a.tar.gz |
MAINT: refactor "for ... in range(len(" statements
Diffstat (limited to 'numpy/lib/polynomial.py')
-rw-r--r-- | numpy/lib/polynomial.py | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/numpy/lib/polynomial.py b/numpy/lib/polynomial.py index 23021cafa..c40e50a57 100644 --- a/numpy/lib/polynomial.py +++ b/numpy/lib/polynomial.py @@ -152,9 +152,8 @@ def poly(seq_of_zeros): return 1.0 dt = seq_of_zeros.dtype a = ones((1,), dtype=dt) - for k in range(len(seq_of_zeros)): - a = NX.convolve(a, array([1, -seq_of_zeros[k]], dtype=dt), - mode='full') + for zero in seq_of_zeros: + a = NX.convolve(a, array([1, -zero], dtype=dt), mode='full') if issubclass(a.dtype.type, NX.complexfloating): # if complex roots are all complex conjugates, the roots are real. @@ -770,8 +769,8 @@ def polyval(p, x): else: x = NX.asanyarray(x) y = NX.zeros_like(x) - for i in range(len(p)): - y = y * x + p[i] + for pv in p: + y = y * x + pv return y @@ -1273,14 +1272,14 @@ class poly1d: s = s[:-5] return s - for k in range(len(coeffs)): - if not iscomplex(coeffs[k]): - coefstr = fmt_float(real(coeffs[k])) - elif real(coeffs[k]) == 0: - coefstr = '%sj' % fmt_float(imag(coeffs[k])) + for k, coeff in enumerate(coeffs): + if not iscomplex(coeff): + coefstr = fmt_float(real(coeff)) + elif real(coeff) == 0: + coefstr = '%sj' % fmt_float(imag(coeff)) else: - coefstr = '(%s + %sj)' % (fmt_float(real(coeffs[k])), - fmt_float(imag(coeffs[k]))) + coefstr = '(%s + %sj)' % (fmt_float(real(coeff)), + fmt_float(imag(coeff))) power = (N-k) if power == 0: |