How to slice / rebin a categorical axis? #223
Answered
by
kondratyevd
kondratyevd
asked this question in
Q&A
-
from hist import Hist
import boost_histogram as bh
h = Hist.new.StrCat(['A', 'B', 'C']).Double()
subset = ['A','B']
h['A'] # ok
h[['A']] # ok
h[subset] # error: wrong number of indices for histogram
h[[subset]] # error: must be a slice, an integer, or follow the locator protocol
h[bh.loc(subset)] # error: only integer scalar arrays can be converted to a scalar index
# input:
Hist(StrCategory(['A', 'B', 'C']), storage=Double())
rebin_scheme = {
'AB': ['A', 'B'],
'C': ['C']
}
# do something
# output:
Hist(StrCategory(['AB', 'C']), storage=Double()) |
Beta Was this translation helpful? Give feedback.
Answered by
kondratyevd
Sep 15, 2021
Replies: 1 comment
-
Selection lists are available in |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
kondratyevd
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Selection lists are available in
v2.4.0
(#259), which solves my issue. In the example above,h[subset]
works inv2.4.0
.Thanks @henryiii !