c++ - 如何在 xt::filter 中使用相等性?

标签 c++ xtensor

以下代码,

#include <iostream>

#include "xtensor/xadapt.hpp"
#include "xtensor/xarray.hpp"
#include "xtensor/xindex_view.hpp"
#include "xtensor/xio.hpp"
#include "xtensor/xmasked_view.hpp"
#include "xtensor/xview.hpp"

using namespace std;

int main() {
    xt::xarray<float> a = {{1, 2, 3}, {4, 2, 6}, {9, 0, 2}};
    cout << a << endl;
    xt::filter(a, a == 2) = 10;
    cout << a << endl;
}

无法编译以下内容:error: no match for ‘operator==’ (operand types are ‘xt::xarray<float>’ ... and ‘int’)

但是,其他比较运算符按预期工作(>、<、>=、<=)。我不确定operator==是否是故意不实现的,但在它实现之前(如果曾经实现过),是否有解决方法,它是什么?

最佳答案

您可以使用xt::equal(a, b)代替a == b。即

xt::filter(a, xt::equal(a, 2)) = 10;

做你想做的事。

关于c++ - 如何在 xt::filter 中使用相等性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68583581/

相关文章:

c++ - linux C++ 套接字选择循环

c++ - 将 C 风格数组从 xtensor 移至 `xt::array`

c++ - xtensor - Tensor 包装器在运行时引发 trivial_assigner 错误

c++ - 在 xtensor 中过滤多维 View

C++ 从文件中读取

c++ - 找不到 -lsocket,客户端-服务器程序中的编译问题?

c++ - 迭代单个 vector 并删除作为其他元素子集的元素?

c++ - 在 xtensor 中复制 View

python - xtensor 将 numpy 数组传递给具有 xt::xtensor 参数类型的函数

c++ - 楼主绘制的任务栏缩略图预览