473,386 Members | 1,962 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

xz
Let's say I have

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

How to transform a into a 2D vector

vector< vector<double v

?
Apr 4 '08 #1
4 1151
xz
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?
Apr 4 '08 #2
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...
Apr 4 '08 #3
On Apr 4, 11:43*pm, xz <zhang.xi...@gmail.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.
Apr 5 '08 #4
xz
On Apr 5, 1:07 am, Abhishek Padmanabh <abhishek.padman...@gmail.com>
wrote:
On Apr 4, 11:43 pm, xz <zhang.xi...@gmail.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?

Apr 7 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Jiho Han | last post by:
Suppose I have an xml fragment like: <mother> <child name="Bob" sex="M"/> <child name="Jane" sex="F"/> ... </mother> If I wanted to replace the <mother> element to <father> element, what is...
140
by: Oliver Brausch | last post by:
Hello, have you ever heard about this MS-visual c compiler bug? look at the small prog: static int x=0; int bit32() { return ++x; }
4
by: David Rogers | last post by:
Is this sequence about as efficient as I can get for sometimes expanding an array? MyClass MyFunc() { MyClass result = new MyClass ; { // Do stuff that might possibly allocate an array...
21
by: Helge Jensen | last post by:
I've got some data that has Set structure, that is membership, insert and delete is fast (O(1), hashing). I can't find a System.Collections interface that matches the operations naturally offered...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
2
by: JRoughgarden | last post by:
After a customer decides to buy a shopping list, there is generally a need to store/insert one master record and a variable number of child detail records, preferably all wrapped in a transaction....
29
by: calvert4rent | last post by:
I need to some sort of data type that will hold a listing of ID's and their counts/frequency. As I do some processing I get an ID back which I need to store and keep an accurate count for how many...
167
by: darren | last post by:
Hi I have to write a multi-threaded program. I decided to take an OO approach to it. I had the idea to wrap up all of the thread functions in a mix-in class called Threadable. Then when an...
10
by: timor.super | last post by:
Hi all, Imagine I've an array of int : int anArray = new int; I want to extract all the integer that are superior to 500 I can do :
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.