gpt4 book ai didi

indexing - Xtensor 返回索引,其中值为 NaN

转载 作者:行者123 更新时间:2023-12-04 10:25:35 25 4
gpt4 key购买 nike

假设我有一个张量:

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, nan, 4, nan}}

我想返回有 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com