vector

Cosine similarity of vectors

Hi how do i find the cosine similarity between vectors. I need to find the similarity to measure the relatedness between two lines of text.Can someone help me with the code.what java classes and methods to use. For example i ve two sentences like 1.system for user interface and 2.user interface machine and their respective vectors afte...

Permutation of a vector

Hello, suppose I have a vector: 0 1 2 3 4 5 [45,89,22,31,23,76] And a permutation of its indices: [5,3,2,1,0,4] Is there an efficient way to resort it according to the permutation thus obtaining: [76,31,22,89,45,23] Using at most O(1) additional space? ...

How to check if m n-sized vectors are linearly independent?

Disclaimer This is not strictly a programming question, but most programmers soon or later have to deal with math (especially algebra), so I think that the answer could turn out to be useful to someone else in the future. Now the problem I'm trying to check if m vectors of dimension n are linearly independent. If m == n you can just bui...

How to approximate a vector contour from an elevation raster?

I have an elevation map stored as a raster. I'd like to fit a smooth "vector" curve to the contours of constant elevation. In my application, the data are actually geographic elevations, but the problem could be generalized to any function of two variables. I can produce another raster with anti-aliased contour lines, and use that as in...

Designing a lazy vector: problem with const

I wrote a little "lazy vector" class (or, delayed vector) which is supposed to look like a std::vector and usable wherever a std::vector is used, but it loads its elements "lazily", i.e. it will load element n (and possibly a few more) from disk whenever someone accesses element n. (The reason is that in my app, not all elements fit into...

Is there a better way to print a string with cout up to N characters?

-edit- I am sending binary and not a string. My test is using html pages so in this example i am only using a string but my question is about binary, vectors and debugging with ostream. I make this clears some confusion. I have the following code: cout << string(&v[0]).substr(0, len); Is there a better way to print the string v with ...

How do generics (Vector) work inside the AVM?

Support for generics (currently only Vector.<*>, and called 'postfix type parameters' by Adobe) was added in Flash Player 10, but the only AVM2 documentation does not describe how these objects are accessed. Specifically, I noticed a new opcode (0x53) and a new multiname kind (0x1D) that seem relevant, but their usage is not documented....

STL-like vector with arbitrary index range

What I want is something similar to STL vector when it comes to access complexity, reallocation on resize, etc. I want it to support arbitrary index range, for example there could be elements indexed from -2 to +7 or from +5 to +10. I want to be able to push_front efficiently. Also I want two-way resize... I know I could write something...

What is the overhead cost of an empty vector?

What is the memory overhead of having an empty vector vs having a pointer to a vector? Option A: std::vector<int> v; Option B: std::vector<int> *v = NULL; I believe that option B takes 1 32 bit pointer (assuming 32 bit here) How much memory does the empty 'v' take up? ...

How to find an item in a std::vector?

All I wanna do is to check whether an element exists in the vector or not, so I can deal with each case. if ( item_present ) do_this(); else do that(); ...

NoElementException but I print the element and get the expected result

What I am trying to do is save a Move objects into a Vector called topMoves. There will be many Move objects which is why I create the object within the loop. The pastPriceMap stores prices for stocks at some past time (in this case one minute ago). The currPriceMap stores price for stocks some time within the last second. I get the fo...

Why is a C++ Vector called a Vector?

The question's pretty self-explanatory really. I know vaguely about vectors in maths, but I don't really see the link to C++ vectors. Thanks! ...

Vectors, iterators and std::find

Is there any way to use different types of iterators in different vectors? Or, is there a function that returns the position of element in vector as an integer? std::vector<DWORD>::iterator it; // Iterator // monsterQueue is a <DWORD> vector it = std::find(bot.monsterQueue.begin(), bot.monsterQueue.end(), object); // Check do w...

How do I return hundreds of values from a C++ function?

In C++, whenever a function creates many (hundreds or thousands of) values, I used to have the caller pass an array that my function then fills with the output values: void computeValues(int input, std::vector<int>& output); So, the function will fill the vector output with the values it computes. But this is not really good C++ style...

shrinking a vector

Hi there, I've got a problem with my terrain engine (using DirectX). I'm using a vector to hold the vertices of a detail block. When the block increases in detail, so the vector does. BUT, when the block decreases its detail, the vector doesn't shrink in size. So, my question: is there a way to shrink the size of a vector? I did try t...

Vector Array

I am suppose to create a vector array in C to use in my project. I have not worked with such data structure before, and can't seem to find good information on it. Can you provide a link to information or post the information which describes this data structure in regard to its usage, benefits, and the functions it has. An implementatio...

Removing a custom object from a Java Vector.

I have MyClass, which stores two integers, and I have a Vector<MyClass> called myVector. Now, I do this: ... myVector.add(new MyClass(1,1)); for(MyClass m : myVector) System.out.println(m); System.out.println(myVector.size()); myVector.remove(new MyClass(1,1)); for(MyClass m : myVector) System.out.println(m); System.out.printl...

Can any one recommend a vector graphics engine for reporting purposes?

Need to develop a .NET solution to graphically represent seats in sections, plotted in a stadium layout view, and output as a report... the seats would have different colours displaying sales status... ...

Accessing vector elements inside another vector through an iterator?

std::vector< std::vector<coords> >::iterator iter; for(iter = characters.begin(); iter != characters.end(); iter++) { std::vector<coords>* cha = iter; // doesn't work. } // does work. std::vector<coords>* character = &characters.at(0); coords* first = &character->at(0); And I don't get why. Isn't iter supposed to be a pointer to an ...

When would you use an array rather than a vector/string?

I'm a beginner C++ programmer and so I've learnt using arrays rather than vectors (this seems to be the general way to do things, then move on to vectors later on). I've noticed that a lot of answers on SO suggest using vectors over arrays, and strings over char arrays. It seems that this is the "proper" way to code in C++. That all be...