Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Unintuitive behavior of np.clip on inconsistent amin and amax #5142

Open
@anntzer

Description

@anntzer

If a_min > a_max, the results can get a bit strange:

>>> np.clip(0, 1, 0)
1
>>> np.clip(1, 1, 0)
0

Now this can arguably be blamed on faulty inputs, and a precise reading of the docs (it returns "An array with the elements of a, but where values < a_min are replaced with a_min, and those > a_max with a_max.") explains that behavior (once we realize that the two tests have to be made one after the other), but throwing a ValueError (possibly silenceable/activatable by a keyword switch) could be helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions