Open
Description
The function piecewise(x, condlist, funclist)
returns an output which has the same dtype
as the input x
. However, this input is processed by one of the functions in funclist
and thus it should return an array which dtype same as those function's output.
for example
def func1(v):
return v + 0.1
def func2(v):
return v + 0.2
funclist = [func1, func2]
condlist = [[True, False], [False, True]]
x = np.array([1, 2])
np.piecewise(x, condlist, funclist)
# array([1, 2])
However, the actual expected answer should be array([1.1, 2.2]), which can be attained, but we must make sure the input is specified with float
dtype, e.g.: x = array([1.0, 2.0])
.
Since we have functions here operating on each element of x
, we expect the output to be same as functions outputs.
NumPy/Python version information:
1.19.5 3.7.9 (default, Aug 31 2020, 12:42:55)
[GCC 7.3.0]