diff options
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)) |