Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Equivalent of numpy.where for awkward arrays #84

Open
jpivarski opened this issue Feb 22, 2019 · 3 comments
Open

Equivalent of numpy.where for awkward arrays #84

jpivarski opened this issue Feb 22, 2019 · 3 comments
Labels
enhancement New feature or request

Comments

@jpivarski
Copy link
Member

numpy.where is not a ufunc, but it's useful!

@jpivarski jpivarski self-assigned this Feb 28, 2019
@jpivarski jpivarski added the enhancement New feature or request label Feb 28, 2019
@nsmith-
Copy link
Contributor

nsmith- commented Mar 13, 2019

The non-ternary usage is equivalent to nonzero, e.g. np.where(array<1.) and (array < 1.).nonzero()
So that would be nice to also implement, as it is not currently present in JaggedArray. A (admittedly concise) workaround is
array.index[array<1.]

@nsmith-
Copy link
Contributor

nsmith- commented Mar 15, 2019

The ternary usage is necessary since fancy indexing doesn't work for __setitem__, e.g.

array[array<0] = 0

is supported in numpy but not awkward because of immutability.

array = awkward.where(array<0, 0, array)

could broadcast as appropriate.

@jpivarski
Copy link
Member Author

jpivarski commented Oct 16, 2019

You know, if the type is a (possibly jagged) number, like Clemen's problem on https://stackoverflow.com/a/58345579/1623645 , awkward.where could be implemented like this:

def where(predicate, iftrue, iffalse):
    predicate = predicate.astype(numpy.bool)   # just to make sure they're 0/1
    return predicate*iftrue + (1 - predicate)*iffalse

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants