From aeae93b6c0042f6ed8f45205545985cc194f84f3 Mon Sep 17 00:00:00 2001 From: Marten van Kerkwijk Date: Sun, 3 Jan 2021 11:11:15 -0500 Subject: 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). --- numpy/lib/function_base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'numpy/lib/function_base.py') 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 -- cgit v1.2.1