vector

How to return a 2 dimensional vector ?

I have a function that creates a 2D vector void generate(int n) { vector< vector<int> > V (n, vector<int>(1 << n , 0 )); ....... }//n is used to determine the size of vector Now, I need to return the created vector to use it in another function .If I did return V ; it will be wrong because V is a local variable but I can't ...

resize a 4d vector

How can I resize a 4d vector in C++? ...

Invalid syntax problem with Python (running pygame)

I've been using The New Boston tutorial (http://www.youtube.com/watch?v=x9M3R6igH2E) on how to program with pygame and I keep getting an "invalid syntax" error on the print self.diff command. Only the self is highlighted. Here is the code (i've bolded the problem): class vector(object): def __init__(self, list1, list2): self.diff=(...

How to fill std::vector with data from another vector that meets some criteria

Hi, I have a vector of points, and I need to get those which are at a distance less than a value from a given point. I could do it with a simple loop, but is there a better way to do it? Thanks in advance ...

vector of variable names in R

I'd like to create a function that automatically generates uni and multivariate regression analyses, but I'm not able to figure out how I can specify *variables in vectors...*This seems very easy, but skimming the documentation I havent figured it out so far... Easy example a<-rnorm(100) b<-rnorm(100) k<-c("a","b") d<-c(a,b) summary(k[...

Strange problem with the vector when calculating values to a member.

This is an updated follow-up from my last question: http://stackoverflow.com/questions/3494178/fatal-error-from-incrementing-loop I've finished the sorting algorithm, which seems to work fine. Now my problem is trying to calculate the health for each fighter(in the getHealth() function) based on levels in my vector to calculate correctly...

R: Count number of entries in a row based on external criteria

Dear R-wizards, I have the following data frame: Date1 Date2 Date3 Date4 Date5 1 25 April 2005 10 May 2006 28 March 2007 14 November 2007 1 April 2008 2 25 April 2005 10 May 2006 28 March 2007 14 November 2007 1 April 2008 3 29 January 2008...

Problem with leading zero's in a vector array of doubles

Hi, I'm tring to calculate the standard deviation of a vector of doubles (called A). Now I have a function called StDev that will do this. However, the first few elements of vector A are zero and I need to remove these. To do this I create a sub-array and then pass this to my StDev function as follows: std::vector<double> Array(f...

base class 'class std::vector<...>' has a non-virtual destructor

One of my C++ classes derives from std::vector so that it can act as a container that also perform custom actions on its content. Unfortunately, the compiler complains about the destructor not to be virtual, which I cannot change, since its in the standard library. Am I doing the whole thing wrong (thou shall not derive from STL) or is ...

3D rotation algorithm needed

Given two orthogonal unit vectors, A and B, and two different orthogonal unit vectors C and D, I need the 3x3 direction cosine matrix or a quaternion which will rotate A to align with C AND will rotate B to align with D. The vectors are all 3-vectors (x, y, z). I have a brute force algorithm, but I am almost certain there is a much sim...

Adding vectors of doubles of differing sizes in C++

Hi, I have a number of vector containers of varying size each containing doubles. I would like to add the elements of each vector to create a single vector of doubles. This simple example will example what I'm talking about: Consider two vectors A with three elements 3.0 2.0 1.0 and B with two elements 2.0 1.0. I would like to ad...

Iterating C++ vector

Is it possible to iterate a vector from the end to the begin? for (vector<my_class>::iterator i = my_vector.end(); i != my_vector.begin(); /* ?! */ ) { } Or is that only possible with something like that: for (int i = my_vector.size() - 1; i >= 0; --i) { } ...

Yet another C++ vector memory leak question

Hiya. I'm attempting to make an algorithm that can draw the entities of my isometric game in the correct order. My entities are stored in a vector of pointers. In the drawing function I first create a new vector of the same pointers, and then start with a for-loop that loops the amount of entities that I want to have drawn. Inside that...

Combining vectors of string's

Hi, I have a number of vectors of strings each containing dates. As a simple example vector A of size 2 might contain: A[0] = "01-Jul-2010"; A[1] = "03-Jul-2010"; while a second vector B of size 3 might contain: B[0] = "02-Jul-2010"; B[1] = "03-Jul-2010"; B[2] = "04-Jul-2010"; I'd like to form a vector C which contains the ...

vector space model algorithm in Java to get the similarity score between two people

Hello all, I am trying to use/implement a vector space model algorithm in Java to get the similarity score between two people based on its keywords. So I have the following classes: Person - Has a List of keywords; Keyword - String text; Integer score; The keyword score is the number of mentions the person has made to the keyword. ...

MSVC 10 + Luabind + std::vector == refuse to compile.

So, I have a code, that compiled on MSVC 9 and some previous (dunno how far back it goes...), GCC, MingW, GCC on Mac... But one line, does not compile on MSVC: class_< vector<unsigned int> >("LayerList") .def(constructor<>()) .def("GetCount", &vector<unsigned int>::size) .def("Get", &NumberGet) .def("Add", &vector<unsigned int>::push_...

Scanning an array in R

I use R and I have a long numeric vector. I would like to look for all the maximal continuous subranges in this vector, where all values are lower then some threshold. For example, if the given vector is 5 5 6 6 7 5 4 4 4 3 2 1 1 1 2 3 4 5 6 7 6 5 4 3 2 2 3 4 4 and my threshold is 4 (i.e., =<3), then the values that meet this conditi...

Possible to elegantly convert std:vector to cliext::vector or cli::array<T>?

How's that for a catchy title? I need to convert back and forth from a CLR compliant type, like an array, and a std::vector type. Are there any adapter methods out there, or should I just keep copying it in and out each time I call one of my native methods? There are some interesting methods for converting between the cliext STL var...

c+ stl sorted vector inplace union

I'd like an efficient method for doing the inplace union of a sorted vector with another sorted vector. By inplace, I mean that the algorithm shouldn't create a whole new vector or other storage to store the union, even temporarily. Instead, the first vector should simple grow by exactly the number of new elements. Something like: vo...

Sort and optimize Java Vector with custom objects

I have to optimize Java Vector with "class Row_i" - objects (see below), which describes two series(A and B) of number ranges (startPos - endPos) are equal in every row. This vector has to be sorted and optimized. Group/Sort Criterias: 1 - Row grouping by id_A, 2 - Row grouping by id_B, 3 - Row grouping by startPosA, 4 - Row grouping...