如何将 xt::sum 表达式结果转换为整数
How to convert xt::sum expression result to an integer
我刚刚开始使用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
?
xt::sum 将返回一个 "xtensor type" (xexpression(。它指出"仅在访问或将表达式分配给容器时计算值"。因此,要获得所需的值,请尝试以下操作:
xt::xtensor<double, 1> egoLaneLeftCount = { 1, 1, 1, 0, 0 };
int x = xt::sum(xt::where(egoLaneLeftCount, 1, 0))[0];
相关文章:
- 为什么在逗号分隔符上下文中将预增量的结果强制转换为void
- 尝试将字符串/字符转换为整数会产生意外结果
- Static_cast转换为错误的数据类型,但结果仍然正确?
- 是否可以将无符号 int 的最大值转换为 int 并将结果转换为 -1?
- 使用 sprintf 和 %g 将双精度转换为字符串的意外结果
- 字符到int8_t转换会产生意想不到的结果?
- 将字符串强制转换为GUID并不能得到正确的结果
- 转换为标准时,Clang和GCC中的不同结果::可选<T>
- 如何将 xt::sum 表达式结果转换为整数
- 将函数的地址转换为UINTPTR_T给我不正确的结果
- std::reduce 似乎将结果转换为整数
- 硬编码字符串与强制转换为 PUCHAR 并打印到控制台时从控制台读取的字符串的结果不同
- 为什么在 C# 中将 ushort 端口号从 hton 转换为 ntohs 会给出不同的结果
- time_t提高日期转换,给出不正确的结果
- 将词法强制转换双倍提升为字符串,给出无效结果
- 尝试将二进制数组转换为十六进制C++然后打印结果
- 在C++中将 sqlite 结果转换为 std::string
- 将inet_ntop的结果转换为字符串
- 无法将std::bind的结果转换为std::函数
- 在使用/Wp64进行编译时,如何在不发出警告的情况下将strlen的结果转换为int