Get row vector of 2d vector in C++What are the differences between a pointer variable and a reference variable in C++?How can I profile C++ code running on Linux?The Definitive C++ Book Guide and ListC++ STL Vectors: Get iterator from index?C++ Singleton design patternWhat is the “-->” operator in C++?Appending a vector to a vectorWhy are elementwise additions much faster in separate loops than in a combined loop?Image Processing: Algorithm Improvement for 'Coca-Cola Can' RecognitionReplacing a 32-bit loop counter with 64-bit introduces crazy performance deviations

How to run a prison with the smallest amount of guards?

How does the UK government determine the size of a mandate?

What does the word "Atten" mean?

Do all network devices need to make routing decisions, regardless of communication across networks or within a network?

Type int? vs type int

How can a function with a hole (removable discontinuity) equal a function with no hole?

How easy is it to start Magic from scratch?

How do I find the solutions of the following equation?

Purchasing a ticket for someone else in another country?

Why escape if the_content isnt?

Customer Requests (Sometimes) Drive Me Bonkers!

Is exact Kanji stroke length important?

How do I extract a value from a time formatted value in excel?

How does Loki do this?

For a non-Jew, is there a punishment for not observing the 7 Noahide Laws?

System.debug(JSON.Serialize(o)) Not longer shows full string

Sort a list by elements of another list

Lay out the Carpet

How to Reset Passwords on Multiple Websites Easily?

Method to test if a number is a perfect power?

Is there a good way to store credentials outside of a password manager?

How long to clear the 'suck zone' of a turbofan after start is initiated?

Why Were Madagascar and New Zealand Discovered So Late?

Is a stroke of luck acceptable after a series of unfavorable events?



Get row vector of 2d vector in C++


What are the differences between a pointer variable and a reference variable in C++?How can I profile C++ code running on Linux?The Definitive C++ Book Guide and ListC++ STL Vectors: Get iterator from index?C++ Singleton design patternWhat is the “-->” operator in C++?Appending a vector to a vectorWhy are elementwise additions much faster in separate loops than in a combined loop?Image Processing: Algorithm Improvement for 'Coca-Cola Can' RecognitionReplacing a 32-bit loop counter with 64-bit introduces crazy performance deviations













0















I have a vector of vector in C++ defined with: vector < vector<double> > A;



Let's suppose that A has been filled with some values. Is there a quick way to extract a row vector from A ?



For instance, A[0] will give me the first column vector, but how can I get quicky the first row vector?










share|improve this question

















  • 1





    strictly speaking in your vector<vector>> there is no row-vector. If you want one you need to construct it. Depending on what you want you should consider to have a view rather than creating a new container

    – user463035818
    Mar 7 at 12:50












  • I guess I'm misunderstanding things but wouldn't A[0] be the first row?

    – c_student
    Mar 7 at 12:55







  • 1





    @c_student its a matter of convention, swap "row" with "column" and the question is still the same

    – user463035818
    Mar 7 at 12:58






  • 4





    If this is supposed to be a matrix, you shouldn't use vector<vector<double>> (memory locality, allocations). Look at Eigen, it has all you need!

    – Tobi
    Mar 7 at 12:58











  • what did you try? why is it too slow? what to you need the row vector for? I am afraid without more context you cannot get a better answer than "create a new vector and fill it via looping over your matrix"

    – user463035818
    Mar 7 at 13:00















0















I have a vector of vector in C++ defined with: vector < vector<double> > A;



Let's suppose that A has been filled with some values. Is there a quick way to extract a row vector from A ?



For instance, A[0] will give me the first column vector, but how can I get quicky the first row vector?










share|improve this question

















  • 1





    strictly speaking in your vector<vector>> there is no row-vector. If you want one you need to construct it. Depending on what you want you should consider to have a view rather than creating a new container

    – user463035818
    Mar 7 at 12:50












  • I guess I'm misunderstanding things but wouldn't A[0] be the first row?

    – c_student
    Mar 7 at 12:55







  • 1





    @c_student its a matter of convention, swap "row" with "column" and the question is still the same

    – user463035818
    Mar 7 at 12:58






  • 4





    If this is supposed to be a matrix, you shouldn't use vector<vector<double>> (memory locality, allocations). Look at Eigen, it has all you need!

    – Tobi
    Mar 7 at 12:58











  • what did you try? why is it too slow? what to you need the row vector for? I am afraid without more context you cannot get a better answer than "create a new vector and fill it via looping over your matrix"

    – user463035818
    Mar 7 at 13:00













0












0








0








I have a vector of vector in C++ defined with: vector < vector<double> > A;



Let's suppose that A has been filled with some values. Is there a quick way to extract a row vector from A ?



For instance, A[0] will give me the first column vector, but how can I get quicky the first row vector?










share|improve this question














I have a vector of vector in C++ defined with: vector < vector<double> > A;



Let's suppose that A has been filled with some values. Is there a quick way to extract a row vector from A ?



For instance, A[0] will give me the first column vector, but how can I get quicky the first row vector?







c++ vector






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 7 at 12:49









VictorVictor

9318




9318







  • 1





    strictly speaking in your vector<vector>> there is no row-vector. If you want one you need to construct it. Depending on what you want you should consider to have a view rather than creating a new container

    – user463035818
    Mar 7 at 12:50












  • I guess I'm misunderstanding things but wouldn't A[0] be the first row?

    – c_student
    Mar 7 at 12:55







  • 1





    @c_student its a matter of convention, swap "row" with "column" and the question is still the same

    – user463035818
    Mar 7 at 12:58






  • 4





    If this is supposed to be a matrix, you shouldn't use vector<vector<double>> (memory locality, allocations). Look at Eigen, it has all you need!

    – Tobi
    Mar 7 at 12:58











  • what did you try? why is it too slow? what to you need the row vector for? I am afraid without more context you cannot get a better answer than "create a new vector and fill it via looping over your matrix"

    – user463035818
    Mar 7 at 13:00












  • 1





    strictly speaking in your vector<vector>> there is no row-vector. If you want one you need to construct it. Depending on what you want you should consider to have a view rather than creating a new container

    – user463035818
    Mar 7 at 12:50












  • I guess I'm misunderstanding things but wouldn't A[0] be the first row?

    – c_student
    Mar 7 at 12:55







  • 1





    @c_student its a matter of convention, swap "row" with "column" and the question is still the same

    – user463035818
    Mar 7 at 12:58






  • 4





    If this is supposed to be a matrix, you shouldn't use vector<vector<double>> (memory locality, allocations). Look at Eigen, it has all you need!

    – Tobi
    Mar 7 at 12:58











  • what did you try? why is it too slow? what to you need the row vector for? I am afraid without more context you cannot get a better answer than "create a new vector and fill it via looping over your matrix"

    – user463035818
    Mar 7 at 13:00







1




1





strictly speaking in your vector<vector>> there is no row-vector. If you want one you need to construct it. Depending on what you want you should consider to have a view rather than creating a new container

– user463035818
Mar 7 at 12:50






strictly speaking in your vector<vector>> there is no row-vector. If you want one you need to construct it. Depending on what you want you should consider to have a view rather than creating a new container

– user463035818
Mar 7 at 12:50














I guess I'm misunderstanding things but wouldn't A[0] be the first row?

– c_student
Mar 7 at 12:55






I guess I'm misunderstanding things but wouldn't A[0] be the first row?

– c_student
Mar 7 at 12:55





1




1





@c_student its a matter of convention, swap "row" with "column" and the question is still the same

– user463035818
Mar 7 at 12:58





@c_student its a matter of convention, swap "row" with "column" and the question is still the same

– user463035818
Mar 7 at 12:58




4




4





If this is supposed to be a matrix, you shouldn't use vector<vector<double>> (memory locality, allocations). Look at Eigen, it has all you need!

– Tobi
Mar 7 at 12:58





If this is supposed to be a matrix, you shouldn't use vector<vector<double>> (memory locality, allocations). Look at Eigen, it has all you need!

– Tobi
Mar 7 at 12:58













what did you try? why is it too slow? what to you need the row vector for? I am afraid without more context you cannot get a better answer than "create a new vector and fill it via looping over your matrix"

– user463035818
Mar 7 at 13:00





what did you try? why is it too slow? what to you need the row vector for? I am afraid without more context you cannot get a better answer than "create a new vector and fill it via looping over your matrix"

– user463035818
Mar 7 at 13:00












3 Answers
3






active

oldest

votes


















2














There is no "quick" way with that data structure, you have to iterate each column vector and get the value for desired row and add it to temporary row vector. Wether this is fast enough for you or not depends on what you need. To make it as fast as possible, be sure to allocate right amount of space in the target row vector, so it doesn't need to be resized while you add the values to it.



Simple solution to performance problem is to use some existing matrix library, such as Eigen suggested in comments.



If you need to do this yourself (because it is assignment, or because of licensing issues, or whatever), you should probably create your own "Matrix 2D" class, and hide implementation details in it. Then depending on what exactly you need, you can employ tricks like:



  • have a "cache" for rows, so if same row is fetched many times, it can be fetched from the cache and a new vector does not need to be created

  • store data both as vector of row vectors, and vector of column vectors, so you can get either rows or columns at constant time, at the cost of using more memory and making changes twice as expensive due to duplication of data

  • dynamically change the internal representation according to current needs, so you get the fixed memory usage, but need to pay the processing cost when you need to change the internal representation

  • store data in flat vector with size of rows*columns, and calculate the correct offset in your own code from row and column

But it bears repeating: someone has already done this for you, so try to use an existing library, if you can...






share|improve this answer






























    1














    There is no really fast way to do that. Also as pointed out, I would say that the convention is the other way around, meaning that A[0] is actually the first row, rather than the first column. However even trying to get a column is not really trivial, since



    0, 1, 2, 3, 4
    0
    0, 1, 2


    is a very possible vector<vector<double>> A, but there is no real column 1, 2, 3 or 4. If you wish to enforce behavior like same length columns, creating a Matrix class may be a good idea (or using a library).



    You could write a function that would return a vector<double> by iterating over the rows, storing the appropriate column value. But you would have to be careful about whether you want to copy or point to the matrix values (vector<double> / vector<double *>). This is not very fast as the values are not next to each other in memory.






    share|improve this answer




















    • 1





      I wouldn't say there is any kind of "convention" over rows and columns. That's completely arbitrary decision which is which. One way is probably more common, but it's not a convention to follow.

      – hyde
      Mar 7 at 13:40











    • Good point. I guess I would just like to believe that my way is the way everyone does it :D. If there is no performance aspect involved, because when I write it as a literal using over multiple lines, you get that nice row-wise schema.

      – Raven221221221
      Mar 7 at 13:53


















    0














    The answer is: in your case there is no corresponding simple option as for columns. And one of the reasons is that vector> is a particular poorly suited container for multi-dimensional data.



    In multi-dimension it is one of the important design decisions: which dimension you want to access most efficiently, and based on the answer you can define your container (which might be very specialized and complex).



    For example in your case: it is entirely up to you to call A[0] a 'column' or a 'row'. You only need to do it consistently (best define a small interface around which makes this explicit). But STOP, don't do that:



    This brings you to the next level: for multi-dimensional data you would typically not use vector> (but this is a different issue). Look at smart and efficient solutions already existing e.g. in ublas https://www.boost.org/doc/libs/1_65_1/libs/numeric/ublas/doc/index.html or eigen3 https://eigen.tuxfamily.org/dox/



    You will never be able to beat these highly optimized libraries.






    share|improve this answer






















      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55044194%2fget-row-vector-of-2d-vector-in-c%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      There is no "quick" way with that data structure, you have to iterate each column vector and get the value for desired row and add it to temporary row vector. Wether this is fast enough for you or not depends on what you need. To make it as fast as possible, be sure to allocate right amount of space in the target row vector, so it doesn't need to be resized while you add the values to it.



      Simple solution to performance problem is to use some existing matrix library, such as Eigen suggested in comments.



      If you need to do this yourself (because it is assignment, or because of licensing issues, or whatever), you should probably create your own "Matrix 2D" class, and hide implementation details in it. Then depending on what exactly you need, you can employ tricks like:



      • have a "cache" for rows, so if same row is fetched many times, it can be fetched from the cache and a new vector does not need to be created

      • store data both as vector of row vectors, and vector of column vectors, so you can get either rows or columns at constant time, at the cost of using more memory and making changes twice as expensive due to duplication of data

      • dynamically change the internal representation according to current needs, so you get the fixed memory usage, but need to pay the processing cost when you need to change the internal representation

      • store data in flat vector with size of rows*columns, and calculate the correct offset in your own code from row and column

      But it bears repeating: someone has already done this for you, so try to use an existing library, if you can...






      share|improve this answer



























        2














        There is no "quick" way with that data structure, you have to iterate each column vector and get the value for desired row and add it to temporary row vector. Wether this is fast enough for you or not depends on what you need. To make it as fast as possible, be sure to allocate right amount of space in the target row vector, so it doesn't need to be resized while you add the values to it.



        Simple solution to performance problem is to use some existing matrix library, such as Eigen suggested in comments.



        If you need to do this yourself (because it is assignment, or because of licensing issues, or whatever), you should probably create your own "Matrix 2D" class, and hide implementation details in it. Then depending on what exactly you need, you can employ tricks like:



        • have a "cache" for rows, so if same row is fetched many times, it can be fetched from the cache and a new vector does not need to be created

        • store data both as vector of row vectors, and vector of column vectors, so you can get either rows or columns at constant time, at the cost of using more memory and making changes twice as expensive due to duplication of data

        • dynamically change the internal representation according to current needs, so you get the fixed memory usage, but need to pay the processing cost when you need to change the internal representation

        • store data in flat vector with size of rows*columns, and calculate the correct offset in your own code from row and column

        But it bears repeating: someone has already done this for you, so try to use an existing library, if you can...






        share|improve this answer

























          2












          2








          2







          There is no "quick" way with that data structure, you have to iterate each column vector and get the value for desired row and add it to temporary row vector. Wether this is fast enough for you or not depends on what you need. To make it as fast as possible, be sure to allocate right amount of space in the target row vector, so it doesn't need to be resized while you add the values to it.



          Simple solution to performance problem is to use some existing matrix library, such as Eigen suggested in comments.



          If you need to do this yourself (because it is assignment, or because of licensing issues, or whatever), you should probably create your own "Matrix 2D" class, and hide implementation details in it. Then depending on what exactly you need, you can employ tricks like:



          • have a "cache" for rows, so if same row is fetched many times, it can be fetched from the cache and a new vector does not need to be created

          • store data both as vector of row vectors, and vector of column vectors, so you can get either rows or columns at constant time, at the cost of using more memory and making changes twice as expensive due to duplication of data

          • dynamically change the internal representation according to current needs, so you get the fixed memory usage, but need to pay the processing cost when you need to change the internal representation

          • store data in flat vector with size of rows*columns, and calculate the correct offset in your own code from row and column

          But it bears repeating: someone has already done this for you, so try to use an existing library, if you can...






          share|improve this answer













          There is no "quick" way with that data structure, you have to iterate each column vector and get the value for desired row and add it to temporary row vector. Wether this is fast enough for you or not depends on what you need. To make it as fast as possible, be sure to allocate right amount of space in the target row vector, so it doesn't need to be resized while you add the values to it.



          Simple solution to performance problem is to use some existing matrix library, such as Eigen suggested in comments.



          If you need to do this yourself (because it is assignment, or because of licensing issues, or whatever), you should probably create your own "Matrix 2D" class, and hide implementation details in it. Then depending on what exactly you need, you can employ tricks like:



          • have a "cache" for rows, so if same row is fetched many times, it can be fetched from the cache and a new vector does not need to be created

          • store data both as vector of row vectors, and vector of column vectors, so you can get either rows or columns at constant time, at the cost of using more memory and making changes twice as expensive due to duplication of data

          • dynamically change the internal representation according to current needs, so you get the fixed memory usage, but need to pay the processing cost when you need to change the internal representation

          • store data in flat vector with size of rows*columns, and calculate the correct offset in your own code from row and column

          But it bears repeating: someone has already done this for you, so try to use an existing library, if you can...







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 7 at 13:11









          hydehyde

          32k1589133




          32k1589133























              1














              There is no really fast way to do that. Also as pointed out, I would say that the convention is the other way around, meaning that A[0] is actually the first row, rather than the first column. However even trying to get a column is not really trivial, since



              0, 1, 2, 3, 4
              0
              0, 1, 2


              is a very possible vector<vector<double>> A, but there is no real column 1, 2, 3 or 4. If you wish to enforce behavior like same length columns, creating a Matrix class may be a good idea (or using a library).



              You could write a function that would return a vector<double> by iterating over the rows, storing the appropriate column value. But you would have to be careful about whether you want to copy or point to the matrix values (vector<double> / vector<double *>). This is not very fast as the values are not next to each other in memory.






              share|improve this answer




















              • 1





                I wouldn't say there is any kind of "convention" over rows and columns. That's completely arbitrary decision which is which. One way is probably more common, but it's not a convention to follow.

                – hyde
                Mar 7 at 13:40











              • Good point. I guess I would just like to believe that my way is the way everyone does it :D. If there is no performance aspect involved, because when I write it as a literal using over multiple lines, you get that nice row-wise schema.

                – Raven221221221
                Mar 7 at 13:53















              1














              There is no really fast way to do that. Also as pointed out, I would say that the convention is the other way around, meaning that A[0] is actually the first row, rather than the first column. However even trying to get a column is not really trivial, since



              0, 1, 2, 3, 4
              0
              0, 1, 2


              is a very possible vector<vector<double>> A, but there is no real column 1, 2, 3 or 4. If you wish to enforce behavior like same length columns, creating a Matrix class may be a good idea (or using a library).



              You could write a function that would return a vector<double> by iterating over the rows, storing the appropriate column value. But you would have to be careful about whether you want to copy or point to the matrix values (vector<double> / vector<double *>). This is not very fast as the values are not next to each other in memory.






              share|improve this answer




















              • 1





                I wouldn't say there is any kind of "convention" over rows and columns. That's completely arbitrary decision which is which. One way is probably more common, but it's not a convention to follow.

                – hyde
                Mar 7 at 13:40











              • Good point. I guess I would just like to believe that my way is the way everyone does it :D. If there is no performance aspect involved, because when I write it as a literal using over multiple lines, you get that nice row-wise schema.

                – Raven221221221
                Mar 7 at 13:53













              1












              1








              1







              There is no really fast way to do that. Also as pointed out, I would say that the convention is the other way around, meaning that A[0] is actually the first row, rather than the first column. However even trying to get a column is not really trivial, since



              0, 1, 2, 3, 4
              0
              0, 1, 2


              is a very possible vector<vector<double>> A, but there is no real column 1, 2, 3 or 4. If you wish to enforce behavior like same length columns, creating a Matrix class may be a good idea (or using a library).



              You could write a function that would return a vector<double> by iterating over the rows, storing the appropriate column value. But you would have to be careful about whether you want to copy or point to the matrix values (vector<double> / vector<double *>). This is not very fast as the values are not next to each other in memory.






              share|improve this answer















              There is no really fast way to do that. Also as pointed out, I would say that the convention is the other way around, meaning that A[0] is actually the first row, rather than the first column. However even trying to get a column is not really trivial, since



              0, 1, 2, 3, 4
              0
              0, 1, 2


              is a very possible vector<vector<double>> A, but there is no real column 1, 2, 3 or 4. If you wish to enforce behavior like same length columns, creating a Matrix class may be a good idea (or using a library).



              You could write a function that would return a vector<double> by iterating over the rows, storing the appropriate column value. But you would have to be careful about whether you want to copy or point to the matrix values (vector<double> / vector<double *>). This is not very fast as the values are not next to each other in memory.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Mar 7 at 13:55

























              answered Mar 7 at 13:29









              Raven221221221Raven221221221

              1017




              1017







              • 1





                I wouldn't say there is any kind of "convention" over rows and columns. That's completely arbitrary decision which is which. One way is probably more common, but it's not a convention to follow.

                – hyde
                Mar 7 at 13:40











              • Good point. I guess I would just like to believe that my way is the way everyone does it :D. If there is no performance aspect involved, because when I write it as a literal using over multiple lines, you get that nice row-wise schema.

                – Raven221221221
                Mar 7 at 13:53












              • 1





                I wouldn't say there is any kind of "convention" over rows and columns. That's completely arbitrary decision which is which. One way is probably more common, but it's not a convention to follow.

                – hyde
                Mar 7 at 13:40











              • Good point. I guess I would just like to believe that my way is the way everyone does it :D. If there is no performance aspect involved, because when I write it as a literal using over multiple lines, you get that nice row-wise schema.

                – Raven221221221
                Mar 7 at 13:53







              1




              1





              I wouldn't say there is any kind of "convention" over rows and columns. That's completely arbitrary decision which is which. One way is probably more common, but it's not a convention to follow.

              – hyde
              Mar 7 at 13:40





              I wouldn't say there is any kind of "convention" over rows and columns. That's completely arbitrary decision which is which. One way is probably more common, but it's not a convention to follow.

              – hyde
              Mar 7 at 13:40













              Good point. I guess I would just like to believe that my way is the way everyone does it :D. If there is no performance aspect involved, because when I write it as a literal using over multiple lines, you get that nice row-wise schema.

              – Raven221221221
              Mar 7 at 13:53





              Good point. I guess I would just like to believe that my way is the way everyone does it :D. If there is no performance aspect involved, because when I write it as a literal using over multiple lines, you get that nice row-wise schema.

              – Raven221221221
              Mar 7 at 13:53











              0














              The answer is: in your case there is no corresponding simple option as for columns. And one of the reasons is that vector> is a particular poorly suited container for multi-dimensional data.



              In multi-dimension it is one of the important design decisions: which dimension you want to access most efficiently, and based on the answer you can define your container (which might be very specialized and complex).



              For example in your case: it is entirely up to you to call A[0] a 'column' or a 'row'. You only need to do it consistently (best define a small interface around which makes this explicit). But STOP, don't do that:



              This brings you to the next level: for multi-dimensional data you would typically not use vector> (but this is a different issue). Look at smart and efficient solutions already existing e.g. in ublas https://www.boost.org/doc/libs/1_65_1/libs/numeric/ublas/doc/index.html or eigen3 https://eigen.tuxfamily.org/dox/



              You will never be able to beat these highly optimized libraries.






              share|improve this answer



























                0














                The answer is: in your case there is no corresponding simple option as for columns. And one of the reasons is that vector> is a particular poorly suited container for multi-dimensional data.



                In multi-dimension it is one of the important design decisions: which dimension you want to access most efficiently, and based on the answer you can define your container (which might be very specialized and complex).



                For example in your case: it is entirely up to you to call A[0] a 'column' or a 'row'. You only need to do it consistently (best define a small interface around which makes this explicit). But STOP, don't do that:



                This brings you to the next level: for multi-dimensional data you would typically not use vector> (but this is a different issue). Look at smart and efficient solutions already existing e.g. in ublas https://www.boost.org/doc/libs/1_65_1/libs/numeric/ublas/doc/index.html or eigen3 https://eigen.tuxfamily.org/dox/



                You will never be able to beat these highly optimized libraries.






                share|improve this answer

























                  0












                  0








                  0







                  The answer is: in your case there is no corresponding simple option as for columns. And one of the reasons is that vector> is a particular poorly suited container for multi-dimensional data.



                  In multi-dimension it is one of the important design decisions: which dimension you want to access most efficiently, and based on the answer you can define your container (which might be very specialized and complex).



                  For example in your case: it is entirely up to you to call A[0] a 'column' or a 'row'. You only need to do it consistently (best define a small interface around which makes this explicit). But STOP, don't do that:



                  This brings you to the next level: for multi-dimensional data you would typically not use vector> (but this is a different issue). Look at smart and efficient solutions already existing e.g. in ublas https://www.boost.org/doc/libs/1_65_1/libs/numeric/ublas/doc/index.html or eigen3 https://eigen.tuxfamily.org/dox/



                  You will never be able to beat these highly optimized libraries.






                  share|improve this answer













                  The answer is: in your case there is no corresponding simple option as for columns. And one of the reasons is that vector> is a particular poorly suited container for multi-dimensional data.



                  In multi-dimension it is one of the important design decisions: which dimension you want to access most efficiently, and based on the answer you can define your container (which might be very specialized and complex).



                  For example in your case: it is entirely up to you to call A[0] a 'column' or a 'row'. You only need to do it consistently (best define a small interface around which makes this explicit). But STOP, don't do that:



                  This brings you to the next level: for multi-dimensional data you would typically not use vector> (but this is a different issue). Look at smart and efficient solutions already existing e.g. in ublas https://www.boost.org/doc/libs/1_65_1/libs/numeric/ublas/doc/index.html or eigen3 https://eigen.tuxfamily.org/dox/



                  You will never be able to beat these highly optimized libraries.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 7 at 13:18









                  Ralf UlrichRalf Ulrich

                  15417




                  15417



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55044194%2fget-row-vector-of-2d-vector-in-c%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

                      Алба-Юлія

                      Захаров Федір Захарович