Skip to content

Masking and flattening (using an argmax as a integer-array slice) #584

Answered by jpivarski
tamasgal asked this question in Q&A
Discussion options

You must be logged in to vote

It's not such a corner case—other users might not encounter exactly this case, but probably a similar-enough one.

Since you know each list returned by ak.argmax with keepdims=True has exactly one element (even if that element is None), you can use [:, 0] as a slice to remove the dimension by picking the first (and only) element:

>>> tracks[mask].tolist()
[{'lik': [294.6407542676734]}, {'lik': [96.75133289411137]}, {'lik': [560.2775306614813]}]
>>> tracks[mask][:, 0].tolist()
[{'lik': 294.6407542676734}, {'lik': 96.75133289411137}, {'lik': 560.2775306614813}]

I did a quick check to verify that this also works with empty lists (missing values in the mask).

>>> fewer_tracks = tracks[tracks.lik 

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by tamasgal
Comment options

You must be logged in to vote
2 replies
@jpivarski
Comment options

@tamasgal
Comment options

Comment options

You must be logged in to vote
1 reply
@tamasgal
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants