diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2020-06-01 23:15:32 +0100 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2020-06-01 23:20:07 +0100 |
commit | 3e261be81a5f2645ffc4c1e79a5dccc65a216669 (patch) | |
tree | 1e96ded85ee2b0f376143f092d1a6fd4dae208c6 /numpy/lib/function_base.py | |
parent | 8b901c7f33b7dd76e04df53203c19e1afd80dce7 (diff) | |
download | numpy-3e261be81a5f2645ffc4c1e79a5dccc65a216669.tar.gz |
MAINT: use zip instead of range in piecewise
Minor cleanup while looking at something else.
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r-- | numpy/lib/function_base.py | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 7a23aeab7..4ebca6360 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -604,14 +604,13 @@ def piecewise(x, condlist, funclist, *args, **kw): ) y = zeros(x.shape, x.dtype) - for k in range(n): - item = funclist[k] - if not isinstance(item, collections.abc.Callable): - y[condlist[k]] = item + for cond, func in zip(condlist, funclist): + if not isinstance(func, collections.abc.Callable): + y[cond] = func else: - vals = x[condlist[k]] + vals = x[cond] if vals.size > 0: - y[condlist[k]] = item(vals, *args, **kw) + y[cond] = func(vals, *args, **kw) return y @@ -682,8 +681,7 @@ def select(condlist, choicelist, default=0): choicelist = np.broadcast_arrays(*choicelist) # If cond array is not an ndarray in boolean format or scalar bool, abort. - for i in range(len(condlist)): - cond = condlist[i] + for i, cond in enumerate(condlist): if cond.dtype.type is not np.bool_: raise TypeError( 'invalid entry {} in condlist: should be boolean ndarray'.format(i)) |