#How to insert an element to Eigen::ArrayXd?
8 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
it's not designed with dynamic resizing in mind
if you need to add an element you'll have to manually resize the array and copy the existing elements, plus the new one, into it
like
Eigen::ArrayXd arr(3);
arr << 1, 2, 3;
double newElement = 4.0;
Eigen::ArrayXD newArr(arr.size() + 1);
newArr.head(arr.size()) = arr;
newArr(arr.size()) = newElement;
std::cout << "New array: \n" < newArr < std::endl;
thank you, I find the documents to be pretty hard to read, or is it because I have read too few docs?
I find related information (using resize) on stackoverflow
@frail reef Has your question been resolved? If so, run !solved :)
you'll get better at reading docs over time, but not all docs are created equal - there wouldn't be stuff on stackoverflow if no one else needed help beyond the official documentation. regarding resize: yes, you can also use resize to change the size of Eigen::ArrayXd, but you'll still need to manually copy over the old data and insert the new element, as above