What's the most efficient way to transform a 2d array into a 2dvector

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • xz

    #1

    What's the most efficient way to transform a 2d array into a 2dvector

    Let's say I have

    double a[N][M] = { .......};

    How to transform a into a 2D vector

    vector< vector<double v

    ?
  • xz

    #2
    Re: What's the most efficient way to transform a 2d array into a 2dvector

    But if you wanted that why would
    you start off with a plain 2D array in the first place.

    If you wanna initialize a 2D vector (12x2) with the following data:

    -5, -5,
    -5, 105,
    105, 105,
    105, -5,
    60, -5,
    60, 40,
    70, 40,
    70, 60,
    30, 60,
    30, 40,
    40, 40,
    40, -5,


    How do you do that?

    Comment

    • Brian Tyler

      #3
      Re: What's the most efficient way to transform a 2d array into a 2dvector

      On Fri, 04 Apr 2008 11:43:10 -0700, xz wrote:
      >But if you wanted that why would
      >you start off with a plain 2D array in the first place.
      >
      >
      If you wanna initialize a 2D vector (12x2) with the following data:
      >
      -5, -5,
      -5, 105,
      105, 105,
      105, -5,
      60, -5,
      60, 40,
      70, 40,
      70, 60,
      30, 60,
      30, 40,
      40, 40,
      40, -5,
      >
      >
      How do you do that?
      int arr[2][2]={{-5,-5,},{-5,105}};

      You can probably figure out the rest...

      Comment

      • Abhishek Padmanabh

        #4
        Re: What's the most efficient way to transform a 2d array into a 2dvector

        On Apr 4, 11:43 pm, xz <zhang.xi...@gm ail.comwrote:
        But if you wanted that why would
        you start off with a plain 2D array in the first place.
        >
        If you wanna initialize a 2D vector (12x2) with the following data:
        >
        -5,     -5,
        -5,     105,
        105,    105,
        105,    -5,
        60,     -5,
        60,     40,
        70,     40,
        70,     60,
        30,     60,
        30,     40,
        40,     40,
        40,     -5,
        >
        How do you do that?
        If that is the case, then why do you want to use a vector at all? Why
        don't you work with the arrays only or something like boost:array?
        vectors are not a complete replacement of arrays especially when
        arrays know their size (and they don't grow) and elements at the time
        of creation.

        Comment

        • xz

          #5
          Re: What's the most efficient way to transform a 2d array into a 2dvector

          On Apr 5, 1:07 am, Abhishek Padmanabh <abhishek.padma n...@gmail.com>
          wrote:
          On Apr 4, 11:43 pm, xz <zhang.xi...@gm ail.comwrote:
          >
          >
          >
          But if you wanted that why would
          you start off with a plain 2D array in the first place.
          >
          If you wanna initialize a 2D vector (12x2) with the following data:
          >
          -5, -5,
          -5, 105,
          105, 105,
          105, -5,
          60, -5,
          60, 40,
          70, 40,
          70, 60,
          30, 60,
          30, 40,
          40, 40,
          40, -5,
          >
          How do you do that?
          >
          If that is the case, then why do you want to use a vector at all? Why
          don't you work with the arrays only or something like boost:array?
          vectors are not a complete replacement of arrays especially when
          arrays know their size (and they don't grow) and elements at the time
          of creation.
          What if I want to use some function that reads vector instead of
          array?

          Comment

          Working...