Ach*_*rma 4 numpy c++14 xtensor
我是xtensor的新手.我想知道如何使用xt :: where的输出.在python中,例如假设imap是一个nd数组,np.where(imap> = 4)返回两个带索引的数组,可以使用=运算符直接赋值.请让我知道如何在xtensor C++上下文中使用它.任何小例子都会有很大的帮助.
谢谢.
返回输入类型的xt :: xarray.
xt::xarray<int> res = xt::where(b, a1, a2);
Run Code Online (Sandbox Code Playgroud)
ba1如果返回bfalse元素,a2则返回一个true,然后返回数组元素.
以下示例是从文档(搜索xt::where)中
复制的http://xtensor.readthedocs.io/en/latest/operator.html
b的第一个元素是false- 所以从a211开始
b的第二个元素是true- 所以从a1- 2 获得它
b的第三个元素是true - 所以从a1- 3 获得它
b的第四个要素是false- 所以从a214开始
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 }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
361 次 |
| 最近记录: |