Doing python numpy similar operation in cpp xtensor

142 Views Asked by At

I am converting some python numpy code into C++ code using xtensor library. I am having some issues in indexing based operations. Here is the python code:

Python code

boxes = decoded_boxes[keep, :]
  • keep is a numpy boolean array of dimension [19248]

  • decoded_boxes is a numpy array of dimensions [19248, 4]

  • boxes (output) if a numpy array of dimensions [24, 4]

I am not able to write equivalent code for this. I tried this but did not work.

C++ code

xt::xarray<float> b1 = xt::filter(decoded_boxes, keep); 
std::cout << "b1 shape = " << xt::adapt(b1.shape()) << std::endl; 

gives only {24}.

1

There are 1 best solutions below

0
ABD On

I was able to work around as follows:

auto id = xt::arange(decoded_boxes.shape()[0]);
auto b2 = xt::filter(id, keep);
    
xt::xarray<float> b1 = xt::view(decoded_boxes, xt::keep(b2)); // shape 24, 4