Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Hist from Stack #556

Open
nsmith- opened this issue Jan 5, 2024 · 0 comments
Open

[FEATURE] Hist from Stack #556

nsmith- opened this issue Jan 5, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@nsmith-
Copy link
Contributor

nsmith- commented Jan 5, 2024

Describe the problem, if any, that your feature request is related to

Just as one can construct a Stack from several Hist objects, it may be useful to create a Hist from a Stack by promoting the stack labels to a new StrCategory axis in the histogram.

Describe the feature you'd like

import hist

a = hist.Hist.new.Reg(10, 0, 10, name="blah").Double().fill(3.0)
b = hist.Hist.new.Reg(10, 0, 10, name="blah").Double().fill(5.0)
stack = hist.Stack.from_dict({"a": a, "b": b})

out = hist.Hist(
    hist.axis.StrCategory([s.name for s in stack]),
    *stack.axes,
    storage=stack[0].storage_type()
)
for i, h in enumerate(stack):
    out.view(flow=True)[i, ...] = h.view(flow=True)

Perhaps this is sufficient for an implementation?

Describe alternatives, if any, you've considered

My main motivation here is to be able to use slicing syntax on the stack. If full UHI slicing support were available, with the stack axis treated as a StrCategory, then I would probably not need this feature.

@nsmith- nsmith- added the enhancement New feature or request label Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant