summaryrefslogtreecommitdiff
path: root/numpy/lib/function_base.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2016-01-31 19:01:17 -0700
committerCharles Harris <charlesr.harris@gmail.com>2016-01-31 19:01:17 -0700
commite36d7cab82570b82df3ff0dbc1fc066ae1632768 (patch)
tree50cc73403138bcd9836a17445ce91d3d96e55c91 /numpy/lib/function_base.py
parent2c617599340fb4cd08618b8c396a735909c0789e (diff)
parent46cb649aecc2d5e1a256f78fb3f7879666a7c879 (diff)
downloadnumpy-e36d7cab82570b82df3ff0dbc1fc066ae1632768.tar.gz
Merge pull request #7145 from bastula/piecewise
BUG: Fixed regressions in np.piecewise in ref to #5737 and #5729.
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r--numpy/lib/function_base.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index fc1e15ace..1d9030ec6 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -944,11 +944,16 @@ def piecewise(x, condlist, funclist, *args, **kw):
condlist = condlist.T
if n == n2 - 1: # compute the "otherwise" condition.
totlist = np.logical_or.reduce(condlist, axis=0)
- condlist = np.vstack([condlist, ~totlist])
+ # Only able to stack vertically if the array is 1d or less
+ if x.ndim <= 1:
+ condlist = np.vstack([condlist, ~totlist])
+ else:
+ condlist = [asarray(c, dtype=bool) for c in condlist]
+ totlist = condlist[0]
+ for k in range(1, n):
+ totlist |= condlist[k]
+ condlist.append(~totlist)
n += 1
- if (n != n2):
- raise ValueError(
- "function list and condition list must be the same")
y = zeros(x.shape, x.dtype)
for k in range(n):