【发布时间】:2021-07-20 23:41:17
【问题描述】:
我正在使用 C++,并希望将向量的掩码和搜索验证条件的索引结合起来,类似于 numpy where 函数。
这是一个例子:
std::vector<int> id = {61, 66, 68, 80}
std::vector<int> val = {0, 0, 2, 1};
std::vector<int> offset = {62, 65, 70};
std::vector<int> masked;
使用后
masked = offset[val];
masked 应如下所示:masked = {62, 62, 70, 65}
之后,我想找到id 向量元素大于masked 的索引。两个向量具有相同的长度。这相当于 Python 中 Numpy 的 where 函数。
c = np.where(id > masked)[0]
c 等效于 vector<int>,应如下所示:c = {1,3}
有什么想法吗?谢谢!
【问题讨论】:
标签: python c++ numpy where-clause mask