Skip to content

np.piecewise has the opposite way of resolving ties to np.select #16475

@eric-wieser

Description

@eric-wieser

select is documented specifically to give the first condition priority if multiple are true.
piecewise does not document what happens, but does the opposite:

>>> import numpy as np
>>> x = np.arange(5)

>>> np.piecewise(x, [x > 1, x > 3], [1, 3])
array([0, 0, 1, 1, 3])

>>> np.select([x > 1, x > 3], [1, 3])
array([0, 0, 1, 1, 1])

We should either:

  • Document the fact that piecewise does things in reverse order
  • Swap the order of piecewise, and document the new order
  • Emit a deprecationwarning and eventually a ValueError if multiple conditions are ever true, so that the point becomes moot.

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