我是xtensor的新手。我想知道如何使用来自xt::where的输出。例如,在python中,假设imap是一个数组,np.where(imap>=4)返回两个带索引的数组,可以使用=运算符直接赋值。请告诉我如何在xtensor C++上下文中使用它。任何一个小的例子都会是一个很大的帮助。
谢谢。
发布于 2018-06-12 05:30:57
返回输入类型的xt::xarray。
xt::xarray<int> res = xt::where(b, a1, a2);如果b为true,则返回数组a1的元素;如果b为false,则返回a2的元素。
以下示例复制自documentation (搜索xt::where) http://xtensor.readthedocs.io/en/latest/operator.html
B的第一个元素是false -所以从a2获取它-- 11
B的第二个元素是true -所以从a1获取它-- 2
B的第三个元素是true -所以从a1获取它-- 3
B的第四个元素是false -所以从a2获取它-- 14
xt::xarray<bool> b = { false, true, true, false };
xt::xarray<int> a1 = { 1, 2, 3, 4 };
xt::xarray<int> a2 = { 11, 12, 13, 14 };
xt::xarray<int> res = xt::where(b, a1, a2);
// => res = { 11, 2, 3, 14 }https://stackoverflow.com/questions/50803862
复制相似问题