Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8906379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:38:23+00:00 2026-06-15T02:38:23+00:00

I have a vector<vector<double> , so a table (matrix) of values. Columns contains position

  • 0

I have a vector<vector<double>, so a table (matrix) of values. Columns contains position and velocity of a planet, so rows stores data of the same planet. I want to transform a row in a valarray because I need math operations. Then I want to store the valarrays (the planets) in a vector.
I tried like this:

vector<vector<double>> corps_tmp=configFile.get_corps(); // The function returns a vector<vector<double>>

    valarray<double> corpX;
    for (int i(0); i < corps_tmp.size(); i++) {
        corpX = corps_tmp[i]; // I want to save the first row of the vector<vector<double>> on the valarray
        corps.push_back(corpX); // I want to ''add'' the valarray to a vector.
        corpX = 0;
    }

This code doesn’t works and I obtain an error around the assignment of a vector to a valarray (apparently not permitted).

Is there any way to achieve in a simple way what I tried to do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T02:38:25+00:00Added an answer on June 15, 2026 at 2:38 am

    To create a valarray from a vector:

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

    To write the data back into a vector:

    corps_tmp[i].assign(std::begin(corpX), std::end(corpX));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an (access) database table which contains data I would like to populate
I have a function to display the values of a vector in a table,
I have a function , which is to mulitply a matrix and vector: double
I have the following code: void foo() { vector<double> v(100,1); // line 1 //
I have the following template declaration: template <typename T> void IterTable(int& rIdx, std::vector<double>& rVarVector,
I have a vector where I keep an incrementing data. Normally each element of
I currently have a std::vector which holds std::vector of double. I'd want to sort
I have two vector objects that contain different types of data that are ordered
Suppose, I have a vector with following values in it id = 100 latitude
Suppose I have a Vector datatype defined as follows: data Vector = Vector {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.