indexing - Xtensor 返回值为 NaN 的索引

标签 indexing nan xtensor

假设我有一个张量:

xt::xtensor_fixed<float, xt::xshape<1, 4>, xt::layout_type::column_major> withnans =
 { {3, std::numeric_limits<double>::quiet_NaN(), 4, std::numeric_limits<double>::quiet_NaN()} };

即{{3,南,4,南}}

我想返回有 nan 的位置(索引)。

{1, 3}

我该如何在 xtensor 中执行此操作?

最佳答案

没关系。

xt::xtensor_fixed<float, xt::xshape<1, 4>, xt::layout_type::column_major> withnans =
 { {3, std::numeric_limits<double>::quiet_NaN(), 4, std::numeric_limits<double>::quiet_NaN()} };

std::cout << xt::flatten_indices(xt::argwhere(xt::isnan(xt::flatten(withnans)))) << std::endl;

{3}

关于indexing - Xtensor 返回值为 NaN 的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60641221/

相关文章:

c++ - 选择 2D xtensor 的特定行

c++ - 在 xtensor 中使用 xt::where 时遇到问题

mongodb - 具有 TTL 索引和数据恢复的过期 mongo 数据

sql - 使用哪个索引

c++ - C++中什么情况下会得到nan?

python - Tensorflow 中的加权 Mape

python - 在列表中只出现一次的单词的索引

postgresql - 在更严格的谓词上使用顺序扫描而不是索引扫描

python - 如何将两个数据帧中的两列合并到新数据帧(pandas)的一列中?