Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/160.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 屏蔽并将numpy where函数应用于c++; 我使用C++,并结合向量的掩蔽和对条件验证的索引的搜索,类似于函数中的NUMPY。_Python_C++_Numpy_Where Clause_Mask - Fatal编程技术网

Python 屏蔽并将numpy where函数应用于c++; 我使用C++,并结合向量的掩蔽和对条件验证的索引的搜索,类似于函数中的NUMPY。

Python 屏蔽并将numpy where函数应用于c++; 我使用C++,并结合向量的掩蔽和对条件验证的索引的搜索,类似于函数中的NUMPY。,python,c++,numpy,where-clause,mask,Python,C++,Numpy,Where Clause,Mask,下面是一个例子: std::vector id={61,66,68,80} 向量val={0,0,2,1}; 向量偏移量={62,65,70}; std::矢量屏蔽; 使用后 masked=offset[val]; masked应该是这样的:masked={62,62,70,65} 然后,我想找到id向量元素大于屏蔽的元素的索引。两个向量的长度相同。这相当于Python中Numpy的where函数 c=np.where(id>masked)[0] c相当于vector,应该是这样的:c={

下面是一个例子:

std::vector id={61,66,68,80}
向量val={0,0,2,1};
向量偏移量={62,65,70};
std::矢量屏蔽;
使用后

masked=offset[val];
masked
应该是这样的:
masked={62,62,70,65}

然后,我想找到
id
向量元素大于
屏蔽的
元素的索引。两个向量的长度相同。这相当于Python中Numpy的where函数

c=np.where(id>masked)[0]
c
相当于
vector
,应该是这样的:
c={1,3}


有什么想法吗?谢谢大家!

您可以使用一个简单的循环。请注意,您不需要屏蔽中间数组
。以下是一个(未经测试的)示例:

std::向量c;
c、 储备(价值大小());
对于(大小i=0;i偏移量[val[i]])
c、 推回(i);