Skip to content
Advertisement

mask and apply numpy where function to a vector in c++

I’m using C++ and want to combine the masking of a vector and the search for the indexes where a condition is verified, similarly to the numpy where function.

Here’s an example:

JavaScript

After using

JavaScript

masked should look like this: masked = {62, 62, 70, 65}

Afterwards, I want to find the indexes where id vector elements are greater than masked ones. Both vectors have the same length. This is equivalent to Numpy’s where function in Python.

JavaScript

c is an equivalent of vector<int> and should look like this: c = {1,3}

Any ideas out there? Thank you!

Advertisement

Answer

You can just use a simple loop. Note that you do not need the intermediate array masked. Here is an (untested) example:

JavaScript
Advertisement