1

I have some data stored in a std::vector<std::vector<double>. I used this to create a std::valarray from my std::vector<std::vector<double>.

std:valarray<double> corpX(corps_tmp[i].data(), corps_tmp[i].size());

With this new std:valarray<double> I create a std::vector of corpX, so I obtain an std::vector<std:valarray<double>>. Now I need to store also the first two values of each std::valarray in another std::valarray:

std:valarray<double> position_corps = \\ Concatenation of all the std::valarrays corpsX

How can I accomplish this in a simple way? Thank you!

1 Answers1

1
// assume: std::vector<std::valarray<double>> corpsX;
std::valarray<double> position_corps(corpsX.size());
for (std::size_t i = 0; i < corpsX.size(); ++i) {
    position_corps[std::slice(2 * i, 2, 1)] = corpsX[i][std::slice(0, 2, 1)];
}
musiphil
  • 3,837
  • 2
  • 20
  • 26