hist
hist copied to clipboard
[FEATURE] Hist from Stack
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.