Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

piecewise returns array with same dtype as input, which may have undesired outcomes  #19755

Copy link
Copy link
Open
@dibgerge

Description

@dibgerge
Issue body actions

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]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.