## How do you pass a vectors return type when your calling a function?

IDE that I'm using : Code::Blocks 16.01|Compiler that I'm using : MingGW GCC 6.3.0 Title: How do you pass a vectors return type when your calling a function? Problem(s): I'm trying to to pass the size of a vector called pi as a parameter in the pr...
more »

## How to check if the given value belong to the vectors in list?

Suppose we have a value y=4, and a list of vectors, I want to check if this value belongs to any vector in the list if yes, I will add this value to all the elements of vectors. y<-4 M<- list( c(1,3,4,6) , c(2,3,5), c(1,3,6) ,c(1,4,5,6)) ...
more »

## Sort One Vector Based on the Elements of Another Vector With no Class or Struct

#include <algorithm> #include <fstream> #include <iostream> #include <vector> using namespace std; const int max_applications_num = 1000; vector<string> vector_authors; vector<string> vector_titles; vector<str...
more »

## Sort a vector with a comparator which changes its behavior dynamically

I have a vector of a custom struct and a list of attributes to use for ordering that vector in descending priority. For example: struct TheStruct { artist: String, title: String, date: String, } let order_vec: Vec<String> = vec![...
more »

## Writing function to count number of NA values in vector while ignoring specified indices

I am trying to write a function to count the number of NA values in a vector (specified in the first argument) that will also ignore some indices (specified in a second argument) when making the count. For example, if I have x = c(1,NA,3,4,NA,6,...
more »

## Sort List of Vector3's by specific values

I have a list of Vector 3's and what I want to do is find the Vector3 with the highest X value, if there are multiple Vector3's with the highest X I want to have the Vector 3 with the lowest Y and highest X. I want the method to return the Z of that ...
more »

## Default name concatenation

If I have a named vector v <- c(a = 1, b = 2) And I add them s <- v[2] + v[1] The result is a vector of length one with its element named as the first element in the arithmetic, here "b". You can remove this behavior with double brackets...
more »

## Convert named vector to list in R

Suppose I have the following named numeric vector: a <- 1:8 names(a) <- rep(c('I', 'II'), each = 4) How can I convert this vector to a list of length 2 (shown below)? a.list # \$I # [1] 1 2 3 4 # \$II # [1] 5 6 7 8 Note that as.list(a) is n...
more »

## Element of vector to different columns of data frame

I have a df: group number id 1 A abcd 1 2 A abcd 2 3 A abcd 3 4 A efgh 4 5 A efgh 5 6 B abcd 1 7 B abcd 2 8 B abcd 3 9 B abcd 9 10 B ijkl 10 I want to make it like th...
more »

## Sort vector of pairs: No matching function

I have followed the solution given here to sort a vector of pairs. And I get linear_problem.h:275: error: no matching function for call to ‘sort(std::vector<std::pair<int, double> >::iterator, std::vector<std::pair<int, double...
more »

## Sorting vector based on another sorted vector

I have got a vector1 of pair, sorted by an int key: std::vector <pair <int,string> > vector1; //6 5 1 8 4 2 Then I have another vector2 consisting of numbers contained in vector1: std::vector <string> vector2; //1 5 6 8 How do...
more »

## Apply function to all pairs efficiently

I need a second order function pairApply that applies a binary function f to all unique pairs of a list-like structure and then combines them somehow. An example / sketch: pairApply (+) f [a, b, c] = f a b + f a c + f b c Some research leads me to...
more »

## Create sequence between certain values across two vectors

I am currently trying to create sequences between values of different vectors that do not have the same length. Imagine I have the two following vectors a and b: a<-c(1, 8, 14, 34, 46, 55) b<-c(3, 6, 12, 13, 18, 42, 49, 50, 57, 200) I would...
more »

## Segmentation fault when using recursive method taking vector as input

I'm trying to make a very simple filter using recursion but for some reason, I keep getting these Seg Fault. #include <iostream> #include <vector> #include <math.h> class FilterGeneric { public: std::vector<int> filter(s...
more »

## Class with recursive method using int vector element as input

I'm trying to make a class that have a recursive binary operator taking the input from a vector but for some reason I keep having these error: ||=== Build file: "no target" in "no project" (compiler: unknown) ===| In member function 'int ReduceGener...
more »

## Is there an inplace map function for mutable vectors?

If I have a mutable vector (with type IOVector a for example), is there a map-like function that can modify the elements in place? The vector package provides the modify function but this is only one element at a time. Should I use this or is there ...
more »

## Segmentation fault in recursive function, storing result in a vector

I keep getting this seg fault but I have no idea where it came from. Sorry I'm still new to coding. #include <iostream> #include <vector> using namespace std; vector<int> map(vector<int> v, vector<int>::iterator i, ve...
more »

## Calling member function from another member function's implementation

So I'm defining a class sqmatrix of square matrices for fun and learning, and I've successfully defined a function submat that outputs a submatrix of the object constructed in a certain way: sqmatrix sqmatrix::submat (unsigned int row, unsigned int ...
more »

## Having trouble implementing Vector.sort() on my Vector

I'm aware that it's a trivial matter, still I can't figure out how to implement the sort() function on my Vector. I'll paste the example I'm currently working on: it's a Zoo (that is a Vector of animals) Class Zoo: import java.util.Vector; public c...
more »

## C++ can't push class objects into std::vector

I thought i would be used to the usage of a vector. But somehow im getting problems while pushing class Objects into my std::vector. My vector is declared in my Class : Galaxy: //Galaxy.h #ifndef GALAXIS_H #define GALAXIS_H #include "Stern.h" #inc...
more »

## Iterate throught options with a constrain on each possibility

I have a problem where I need to iterate through many possibilities programatically. Let me give you an example as it'll be far more understandable. I got a vector (or array for simplicity) say [0.4, 0.2, 0.3, 0.1] where every value is between 0 an...
more »

## BLAS Level 2 band matrix-vector product multiple vectors

A routine in BLAS Level 2 for banded matrix vector product exists, both for general and symmetric cases (links for MKL implementation). cblas_?gbmv cblas_?sbmv Is there any way to use multiple vectors (without using an outside for-loop), to maximi...
more »

## When does `modify` copy the vector?

From https://hackage.haskell.org/package/vector-0.12.0.1/docs/Data-Vector.html#v:modify Apply a destructive operation to a vector. The operation will be performed in place if it is safe to do so and will modify a copy of the vector otherwise. T...
more »

## No advantage to contiguous memory vector when elements are pointers or references?

I've been reading about the different containers in the C++ standard library, and I keep on hearing about how the simple vector in practice will often outperform most of the other containers when iterating over the elements. This is said to be due to...
more »

## Moving vector pointer to derived class of vector in C++?

I want to move the pointer of a vector to my the vector of the A object (this). I want to do this because I use my help vector (for mergesort) and I want the values of the help vector in the original vector. I however only want to use 1 operation (so...
more »

## Creating class object in the game loop

I'm wondering how is the proper way to create objects of classes in the game loop once? For example I've Box, Sphere, Cyllinder classes and I want to create several objects at different time while the program is running and work with them in the futu...
more »

## How do I plot a vector field within an arbitrary plane using Python?

I have a 3d velocity vector field in a numpy array of shape (zlength, ylength, xlength, 3). The '3' contains the velocity components (u,v,w). I can quite easily plot the vector field in the orthogonal x-y, x-z, and y-z planes using quiver, e.g. X, ...
more »

## Recycle a vector of characters in negative and positive direction

lets say I have vector of characters, letters and symbols vec<-c(letters, 0:9, LETTERS, c("!","§","\$","%","&")) vec I would like to build a function recycle that can recycle the vector vec so that recycle(vec, 68) would be similar to vec[6...
more »

## C++ vector storing generic T type classes

I have a Foo class that expects T type values. I'd also like to store them in a vector. I've tried several methodologies, but didn't find any solutions. Please have a look at the source code below to get the idea what I'd like to achieve. #include &...
more »

## Run function on vector without sapply

I would like to understand how I can write a function to execute a certain rule on the elements of a vector. Assume I want to multiply by a value all the elements of a vector, the below code returns: a<-c(1, 3, 5, 7, 10) f <-function(x){ f<...
more »

more »

## Trying to pass more than 2 vectors to a function in R

I want to compute e^(ax+b) over a=-1:1 and b=-1:1 for various values of X. I want the output in the form a list of 5 elements. Each element in the list is 3X3 Matrix. I did achieve this using Outer and Vectorize. sigm = function(a=0,b=0,x){ retu...
more »

I'm following an online tutorial on Haskell. We define a function to add two-dimensional vectors, represented by tuple pairs of numbers. The following is the explicit type declaration, that ensures both inputs are two-dimensional vectors. addVectors...
more »

## c++ - sorting a vector of custom structs based on frequency

I need to find the most frequent element in an array of custom structs. There is no custom ID to them just matching properties. I was thinking of sorting my vector by frequency but I have no clue how to do that. ...
more »