Strange error in c++ class construction

I have recently started learning c++ and I am now trying to make a simple vector class as an exercise. But somehow my code doesn't seem to work. #include <iostream> #include <cmath> class Vec2 { public: float x1; float x2; Ve...
more »

2017-05-17 11:05 (4) Answers

C++ Static vectors in classes

I am working on a restraunt order system as a project for my computer science class and I was wondering if it would be best practice to use a static vector within my Order class to contain all of my orders or should I have it in my main program? I'm ...
more »

2017-05-10 22:05 (1) Answers

Vectorizing nearest neighbor computation

I have the following function which is returning an array calculating the nearest neighbor: def p_batch(U,X,Y): return [nearest(u,X,Y) for u in U] I would like to replace the for loop using numpy. I've been looking into numpy.vectorize() as th...
more »

2017-05-08 19:05 (1) Answers

using prolog & clpr for a system of constraints

I'm looking to use prolog in a desktop application to generate a random vector that satisfies a system of constraints. As an example, our user might provide our software with the following information at runtime: Given a vector <x1, x2, x3, ... ...
more »

2017-05-08 09:05 (1) Answers

Sorting 2d vector passed by reference

I implemented Prim's algorithm. It returns a std::vector<std::vector<int>> (which is a vector of vectors : [vertice, vertice, weight]). The results are correct, but when I compare it with my lab guys results, sometimes there is a differen...
more »

2017-05-07 19:05 (1) Answers

How to create a vector between 2 dates in R

I am new to R and I would like to create a vector between 2 dates a Here is my code start.plot <- c("2011-01-01", "2012-12-31") plot1 <- substr(start.plot[1],1,7) plot2 <- substr(start.plot[2],1,7) Month_test <- as.character(seq(as...
more »

2017-05-05 16:05 (1) Answers

Switch input for sorting algorithm

I wrote an insertion sort below: int i, j; Book temp; for (j = 1; j < books.size(); j++) { temp = books[j]; i = j - 1; while (i >= 0) { if (temp.getAuthor().compare(books[i].getAuthor()) > 0) { break; ...
more »

2017-04-28 15:04 (3) Answers

R: Find unique vectors in list of vectors

I have a list of vectors list_of_vectors <- list(c("a", "b", "c"), c("a", "c", "b"), c("b", "c", "a"), c("b", "b", "c"), c("c", "c", "b"), c("b", "c", "b"), c("b", "b", "c", "d"), NULL) For this list I would like to know which vectors are uniqu...
more »

2017-04-21 10:04 (1) Answers

call a function from an array of vectors

In following code, i get an error on line 33. Why? What is the correct syntax? Surely I made some stupid mistake ... unfortunately I'm trying to better understand the vectors. #include <iostream> #include <vector> class firstClass { ...
more »

2017-04-17 17:04 (1) Answers

overloading = operator for self made vector class

I started writing my own vector class and got around to overloading the = operator. I have the code below for something like somevector = someothervector, although I'm not sure it's right, as I'm stuck on making another overload for something like so...
more »

2017-04-10 00:04 (1) Answers

Vector whose elements add up to a value in R

I'm trying to create a vector whose elements add up to a specific number. For example, let's say I want to create a vector with 4 elements, and they must add up to 20, so its elements could be 6, 6, 4, 4 or 2, 5, 7, 6, whatever. I tried to run some l...
more »

2017-04-07 18:04 (2) Answers