boost::histogram::indexed用法详解
在使用直方图库Boost.Histogram时,有时候需要对每个bin的索引进行处理,比如将某个数值映射到对应的bin中。这个时候就可以使用boost::histogram::indexed。
boost::histogram::indexed是boost::histogram库提供的一种用于遍历多维直方图的迭代器,可以获取当前bin的索引和值,并且支持自定义索引类型。下面我们来看一个示例程序:
#include <iostream>
#include <vector>
#include <boost/histogram.hpp>
int main() {
using namespace boost::histogram;
// 定义二维直方图
auto h = make_histogram(axis::regular<>(4, -1.0, 1.0),
axis::variable<>({0.0, 0.5, 0.8, 1.0, 2.0}));
// 填充数据
std::vector<std::pair<double, double>> data = {
{0.1, 0.3}, {-0.5, 2.0}, {0.8, 1.5}};
for (auto&& d : data)
h(d.first,