8000 Fixed bug in numpy.piecewise() · numpy/numpy@e553e1b · GitHub
[go: up one dir, main page]

Skip to content

Commit e553e1b

Browse files
committed
Fixed bug in numpy.piecewise()
Updated numpy/lib/function_base.py to fix bug in numpy.piecewise() for 0-d array handling and boolean indexing with scalars.
1 parent 731cf3a commit e553e1b

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

numpy/lib/function_base.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -673,21 +673,11 @@ def piecewise(x, condlist, funclist, *args, **kw):
673673
"""
674674
x = asanyarray(x)
675675
n2 = len(funclist)
676-
if isscalar(condlist) or \
677-
not (isinstance(condlist[0], list) or
678-
isinstance(condlist[0], ndarray)):
676+
if isscalar(condlist):
679677
condlist = [condlist]
680678
condlist = [asarray(c, dtype=bool) for c in condlist]
681679
n = len(condlist)
682-
if n == n2-1: # compute the "otherwise" condition.
683-
totlist = condlist[0]
684-
for k in range(1, n):
685-
totlist |= condlist[k]
686-
condlist.append(~totlist)
687-
n += 1
688-
if (n != n2):
689-
raise ValueError(
690-
"function list and condition list mus 8000 t be the same")
680+
691681
zerod = False
692682
# This is a hack to work around problems with NumPy's
693683
# handling of 0-d arrays and boolean indexing with
@@ -704,6 +694,16 @@ def piecewise(x, condlist, funclist, *args, **kw):
704694
newcondlist.append(condition)
705695
condlist = newcondlist
706696

697+
if n == n2-1: # compute the "otherwise" condition.
698+
totlist = condlist[0]
699+
for k in range(1, n):
700+
totlist |= condlist[k]
701+
condlist.append(~totlist)
702+
n += 1
703+
if (n != n2):
704+
raise ValueError(
705+
"function list and condition list must be the same")
706+
707707
y = zeros(x.shape, x.dtype)
708708
for k in range(n):
709709
item = funclist[k]

0 commit comments

Comments
 (0)
0