0

我刚开始使用 xtensor,我已经陷入了一个基本问题。

我正在使用类似xt::sum(xt::where(egoLaneLeftCount, 1, 0))对列求和并获得单个整数值的方法。我想将此整数值保存到变量中,但我得到以下内容compilation error

xt::xreducer<xt::xreducer_functors<std::plus<long long int>, xt::const_value<long long int>, std::plus<long long int> >, xt::xfunction<xt::detail::conditional_ternary, const xt::xarray_container<xt::uvector<bool, std::allocator<bool> >, (xt::layout_type)1, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression_tag>&, xt::xscalar<int>, xt::xscalar<int> >, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::reducer_options<long long int, std::tuple<xt::evaluation_strategy::lazy_type> > >

任何人都知道如何将这种数据类型的结果转换为int?

4

1 回答 1

2

xt::sum 将返回一个“xtensor 类型”(xexpression)。它声明“仅在访问或将表达式分配给容器时计算值”。因此,要获得您想要的值,请尝试以下操作:

xt::xtensor<double, 1> egoLaneLeftCount = { 1, 1, 1, 0, 0 };
int x = xt::sum(xt::where(egoLaneLeftCount, 1, 0))[0];
于 2019-10-16T06:09:29.527 回答