diff options
author | Matti Picus <matti.picus@gmail.com> | 2021-09-01 16:51:41 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-01 16:51:41 +0300 |
commit | 68299575d8595d904aff6f28e12d21bf6428a4ba (patch) | |
tree | f59f89c4786b8298fe25ef4f082f51366b388bb3 /numpy/lib/polynomial.py | |
parent | 0656fc493591be2200b0b0df5e14fb547aa4702f (diff) | |
parent | 64f15a94708095bf9d29af5dbfcc4b654a57248a (diff) | |
download | numpy-68299575d8595d904aff6f28e12d21bf6428a4ba.tar.gz |
Merge pull request #19781 from mwtoews/foreach-item
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: |