Tony Shi
Tony Shi

Reputation: 19

quick way to find sub-vector of a cpp vector

Say I have a 4 dimensional C++ std::vector, x. In the numpy's notation, I can easily get access to a sub-vector y=x[:, :, :, 2] using slicing. In cpp, is there a fast way to do this?

A naive way is of course to using 3 for loops with the last dimension fixed to 2 in x. Not sure if there's a better way to handle this senario. And also, is a general solution for this kind of problems in C++, i.e. for an Nd C++ vector, fix arbitrary m number of axes and decay the vector to (N-m)d?

Upvotes: 0

Views: 53

Answers (0)

Related Questions