summaryrefslogtreecommitdiff
path: root/numpy/lib/function_base.py
diff options
context:
space:
mode:
authorMarten van Kerkwijk <mhvk@astro.utoronto.ca>2021-01-03 11:11:15 -0500
committerMarten van Kerkwijk <mhvk@astro.utoronto.ca>2021-02-22 10:37:32 -0500
commitaeae93b6c0042f6ed8f45205545985cc194f84f3 (patch)
tree404f3e80245dabae30b884cbf64b4821b8bc0451 /numpy/lib/function_base.py
parent68e4d56eb9b539cccd582de7e7fb09c373d37609 (diff)
downloadnumpy-aeae93b6c0042f6ed8f45205545985cc194f84f3.tar.gz
API: make piecewise subclass safe using use zeros_like.
Subclass input of piecewise was already respected, so it seems more logical to ensure the output is the same subclass (possibly just an oversight that it was not done before).
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r--numpy/lib/function_base.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index d33a0fa7d..c6db42ce4 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -8,7 +8,7 @@ import numpy as np
import numpy.core.numeric as _nx
from numpy.core import transpose
from numpy.core.numeric import (
- ones, zeros, arange, concatenate, array, asarray, asanyarray, empty,
+ ones, zeros_like, arange, concatenate, array, asarray, asanyarray, empty,
ndarray, around, floor, ceil, take, dot, where, intp,
integer, isscalar, absolute
)
@@ -606,7 +606,7 @@ def piecewise(x, condlist, funclist, *args, **kw):
.format(n, n, n+1)
)
- y = zeros(x.shape, x.dtype)
+ y = zeros_like(x)
for cond, func in zip(condlist, funclist):
if not isinstance(func, collections.abc.Callable):
y[cond] = func