Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of boost. Click here for the latest Boost documentation.

Function template reduce

boost::histogram::algorithm::reduce — Shrink, slice, and/or rebin axes of a histogram.


// In header: <boost/histogram/algorithm/reduce.hpp>

template<typename Histogram, class... Ts> 
  Histogram reduce(const Histogram & hist, const reduce_command & opt, 
                   const Ts &... opts);


Returns a new reduced histogram and leaves the original histogram untouched.

The commands rebin andshrink orslice for the same axis are automatically combined, this is not an error. Passing ashrink and aslice command for the same axis or tworebin commands triggers an invalid_argument exception. It is safe to reduce histograms with some axis that are not reducible along the other axes. Trying to reducing a non-reducible axis triggers an invalid_argument exception.

An overload allows one to pass an iterable of reduce_command.



original histogram.


first reduce command; one of shrink,slice,rebin,shrink_and_rebin, orslice_or_rebin.


more reduce commands.