Questions tagged [vector]

A vector is a single-dimensional array: it contains components that can be accessed using an integral index. In some languages the size of a vector can grow or shrink as needed to accommodate adding and removing items after the Vector has been created. Use 'vector-graphics' for graphic display.

0
votes
0answers
12 views

What should I do better in my vector implementation in C++?

I am starting to learn new features related to C++(templates, l-value, r-value, move, perfect forwarding, etc) and I decided to test what i learned so far by implementing my own vector class. I wanted ...
-2
votes
0answers
21 views

Assistance needed for a program to generate UML type draft of a code

I am trying to write a c++ program that prepares a draft indicating the classes(and their members), functions (and hopefully generate a UML diagram from it sometime). The first step that i identified ...
0
votes
0answers
7 views

How to find the first index (row number) of an element in a 2d vector

We are assigned to make a checker program that takes two input files. The two files contains groupings of 30 students (10 rows and 3 columns) so there are 3 students per group. We need to check if ...
-5
votes
0answers
67 views

What is the difference between vector<int> a(60); and vector<int> a; without the indexind feature [on hold]

What is the difference between vector<int> a(60); and vector<int> a; except the indexind from 0? EDIT: I want to know if vector<int> a(60); is better than vector<int> a; at ...
-2
votes
0answers
48 views

How to push structure vector into structure vector?

Does anyone know how to push structure vectors into structural vectors? Question. I want to push_back Part_vec into Pallet_vec. and cout code for checking. Also i wonder if there is a common way to ...
-3
votes
1answer
25 views

Question about accessing object method with vector iterator

I am new to c++ and I have an assignement on vector/iterators. I ran into a problem that I was able to solve by searching on the internet but unfortunately the forums I visited only provided with the ...
1
vote
0answers
57 views

Basic calculations of vectors in Python

I am writing code that uses calculations based on points of known positions (XYZ) and their velocity (vx, vy, vz). I'm trying to calculate the basic vector calculations for eg. length (L=sqrt(x ** 2+y ...
0
votes
1answer
62 views

How to add an object to a vector and check if it worked

I got a class WayPoint that contains a pair of doubles and a name. I got a class WayPointContainer that contains a vector of Waypoints. WayPointContainer got a method to add a WayPoint to its vector ...
4
votes
2answers
29 views

Converting data.frame to high-dimensional matrix

For example, consider the following data > sample.df f1 f2 x1 x2 x3 1 2 2 7.28 9.40 5.02 2 1 1 6.30 9.56 3.74 3 2 1 6.88 8.72 3.14 4 1 2 6.68 9.58 3.84 I wonder how to write MAGIC ...
3
votes
2answers
75 views

Get a view to all T's in std::vector<std::tuple<Ts…>>

Imagine I have a container which is similar to std::vector<std::tuple<Ts...>>. From that, I would like to get a "view" (non-copying) to all T's such that I can operate on that view as if ...
0
votes
1answer
31 views

TypeError: Bad Operand Type for abs(): 'ReferenceFrame' but I have no abs() function

I'm trying calculate the curl of a vector with its del operator, and so I'm using the curl from sympy and just having the vector cross with the reference frame, but I get this error: what exactly am I ...
1
vote
1answer
61 views

Linux much faster than Windows when reading data from .txt file and placing into vector. How would I speed up Windows to do the same?

I have .txt files for data (100MB - 700MB). When reading these files and placing them into vectors, Linux does this 20-30x faster. Is this a system issue, or is there something I can do to speed up ...
1
vote
2answers
53 views

How do I return a reference to a concrete type that was added to a vector of trait objects?

In this code, I take a vector, create a struct instance, and add it to the vector boxed: trait T {} struct X {} impl T for X {} fn add_inst(vec: &mut Vec<Box<T>>) -> &X { ...
2
votes
1answer
35 views

Split character vector by element in R?

Given a vector: c("kuku", "pupu", "lilu","","ff","rrrr", "", "rrr") How can I split it by ""? To get 3 vectors: c("kuku", "pupu", "lilu") c("ff","rrrr") c("rrr")
-1
votes
0answers
17 views

How to add each word in a sentence of string into vector [duplicate]

Which word appears most in the sentence For example: Apple pen banana pen banana banana pen Output: banana pen Because the two words appear most (3 times). So I want to put every word in ...
-1
votes
0answers
33 views

Replacement of cycles with algorhitms- something goes wrong and I can't understand what am I doing not well

I have a project for the university with three classes and I have a little problem. The program I wrote works, but they told me I have to use algorhitms somewhere and not only for cycles for the maps ...
0
votes
1answer
40 views

Problem with add method vector of 2D-array in java

I have declared a vector of 2D-array in java. At each step I add an array into vector by add() method. But when print out this vector to see what inside, I've got an unexpected output. None of these ...
-3
votes
2answers
31 views

input into vector without pre_defined length…? [on hold]

Suppose, i want to add all the elements in the vector and want to print the result out. the number of elements that i want to enter is not fixed. let the input be: 3 5 2 8 5 34 64 23 10 8 12 5 4 95 ...
-1
votes
1answer
23 views

concatenate two vector from another vector

I have a vector and in every story, I have a vector where are all the string of my story. I need to verify if two stories have the same name and after that concatenate them. histoire is story titre ...
0
votes
1answer
28 views

Dot product between scipy sparse matrix and numpy array give ValueError

I'm trying to calculate the dot product between a scipy parse matrix and a numpy array. First I was using a numpy matrix, which you can see in the following code: def power_iteration(matrix, n): ...
-1
votes
0answers
35 views

How to share array of vector between classes

I would like to get an array of vectors from a class to use it in a separate source file. I had no luck with an array of boolean neither. I have tried to get it through a public method. It works with ...
-3
votes
0answers
34 views

How to cout a function that returns a vector of strings?

To cout a vector of strings is easy, iterate through the vector array. But what if a function returns an array? Is there any way to directly cout the return of the fuction? Otherwise I think I have ...
0
votes
1answer
54 views

Symmetric Matrix in C++

Checking whether a 2D Matrix is symmetric or not Task is to output YES if the matrix is symmetric else output NO. I am not getting the expected result. Can someone please help me out and please let ...
0
votes
0answers
70 views

After the function finished, Why an vector cause the free() error?

I write some codes to calculate the inverse dynamics. It seems that the function IverseDynamicscalculation is finished and return true. Then error occurs: free(): invalid next size (fast): I know ...
0
votes
1answer
29 views

Vectors pointers with vector slices for Tree generation from preorder and inorder vectors

I'm getting the following error: solution.cpp: In member function buildTree Line 26: Char 62: error: no matching function for call to 'Solution::buildTree(__gnu_cxx::__alloc_traits, int>::value_type*...
-1
votes
1answer
28 views

Iterating over const_iterator

ALL, I have a function with the following signature: void foo(const std::vector<Bar *> &myvec); Inside this function I need to loop thru the members of the vector and perform some ...
-1
votes
0answers
38 views

Unsure as to how I get the position of a Texture in SDL from within its class?

Im unsure as to how I get and set the position of a texture once its been rendered onto the screen. Im using SDL and have set up the character class and its relevant header file however how I go about ...
0
votes
0answers
16 views

TypeError for a non-numerical vector, and to do the curl

So I'm trying to solve a problem for a class, and I'm trying to do the curl, but it's in variables. I end up getting a TypeError: 'type' object is not subscriptable. I don't know what I'm doing wrong, ...
0
votes
0answers
49 views

How to copy content from a file into a 2D vector? (C++)

I have a sort of map made out of numbers in a file. I want to read all of it into a 2D vector I created inside a function for it. I have initialized the vectors in 0s. What happens is when I compile ...
0
votes
1answer
41 views

Place objects based on coordinates, not on the central coordinates in Unity

I'm creating mesh objects dynamically based on the screen. So objects that contain mesh objects are always the same size, but mesh objects have different shapes and sizes. I want you to see my ...
0
votes
0answers
51 views

Is it possible to include vector fields in a protobuf message to generate Rust struct?

I have a protobuf file used to generate types in a project. One of the types looks like: syntax = "proto3"; // ... message myStruct { int32 obj_id = 1; string obj_code = 2; string ...
-1
votes
0answers
20 views

Erroneous vector filtering from image based on direction (directional filter)

I am working on the motion estimates using two images by python based algorithm. I got the attached vector field (green color). This field includes some erroneous vector. I want to filter those ...
1
vote
2answers
44 views

What function should I use to return a vector of characters?

So I have a data set that looks like this: gene_id gene_symbol Chr Biotype L001P L003P L004P L005P L008P L010P L012P L014P L016P L017P 2 ENSG00000000003 ...
2
votes
2answers
88 views

convert a byte vector into a vector of floats

I'm sending a fixed length byte stream over a serial port to another computer and I'd like to try and convert the byte stream to a vector of floating point numbers. My stream has a delimiter stop ...
0
votes
0answers
35 views

Why does My Program Not Exit a While Loop that Erases a Vector Position at The End

I'm making a program that sums hexadecimal numbers up to any amount of characters and in the function sumHexArray, the while loop for some reason doesn't exit correctly, and I do not know why. The ...
-2
votes
1answer
43 views

Member vector not maintaining elements when attempting to push from member function

I have a static member function that initializes an Object1, which contains a member vector of a Object2's. Object2 has a member vector of strings. I am trying to add a series of strings to Object2's ...
-2
votes
1answer
42 views

Error in multiplying matrix vector - invalid operands to binary * (have 'double *' and 'double *')

I'm trying to multiply a large and random matrix (NxN) and a random vector (N), using pointers. Why am i getting an error type "invalid operands to binary * (have 'double *' and 'double *')" ? The ...
-3
votes
3answers
57 views

Can we use vector in c++ to take user input of unknown size only till we hit enter?

I was trying to take user input in a vector in c++, as vector is a dynamic data structure i wanted it to take input as long as user wants and when the user hit enter key it should stop taking the ...
1
vote
3answers
47 views

Runtime error when using push_back() on smart pointer to vector

I am trying to fill a vector, by dereferencing a smart-pointer. During runtime the program crashes after one iteration of the first "for" loop used for entering the variable input. using namespace ...
1
vote
1answer
28 views

How do I return a Generic Vector Iterator from an Inline Template method?

OK. As the question states I have an Inline Template method that returns an Iterator to a generic vector. note: I know I should change the implementation to std::find, but that's not the problem I'm ...
1
vote
1answer
21 views

How can i erase element of VECTOR LIST in c++?

I need to erase the element of position 'k' in my code , Suppose i got the '3' in K so i wants to erase member of position 3 in vector list . What is the solution? thanks in advance ! using namespace ...
2
votes
1answer
33 views

output a collection of collections using templated operator<<

I want to output a collection of collection (a vector of vectors in this case) by calling the outside collection once by operator<< It works when I remove the ' ' from the operator<<() ...
0
votes
0answers
17 views

How to run a regression with dates and variables (each variable linked to a stock)?

I am trying to run a regression with dates (lines) and variables (columns). My problem: We haeve 60 stocks and for each of them 5 variables. It is the same variables for each stocks but I have more ...
22
votes
4answers
2k views

Performance gap between vector<bool> and array

I was trying to solve a coding problem in C++ which counts the number of prime numbers less than a non-negative number n. So I first came up with some code: int countPrimes(int n) { vector<...
1
vote
1answer
69 views

strange memory behave of resize and reserve about vector

I know reserve(n) only allocate n space but size is zero. while resize(n) allocate n space and size is n. but when I observe the memory change by window task manager in the test , I'm confused by ...
-1
votes
1answer
44 views

How do i overload operator “[]” for vector containing my own class objects

So i got a class WayPoint (inside the namespace HHN). And i got a class WayPointContainer. The container got a private vector variable to store objects from the type "HHN::WayPoint" What i want to ...
0
votes
1answer
42 views

How to compute a probability matrix based on a binary matrix?

My attempt is: library(igraph) set.seed(41) n<-10 A <- sample.int (2, n*n, TRUE)-1L; dim(A) <- c(n,n); m <- sum(A) g <- graph_from_adjacency_matrix(A) k_in <- degree(g, v = V(...
0
votes
2answers
63 views

how to input structural type vector data into structural vector member (nested structural vector) in c++

I'm beginner and implementing scheduling simulation. I want to insert the structural vector(Order) into the structural member vector(selectedParts) in the Pallet. I know how to insert the int type ...
0
votes
1answer
39 views

search in record set / update value

I created a record set using structs, vector and added couple of records. This is the code that does it. This should run as is - on an Arduino/ESP8266/ESP32. #include <string> #include <...
0
votes
1answer
57 views

Accessing an uninitialized value, most probably in a vector

I am doing an exercise where I need to find a positive integers p and q which are factors of another natural number n. Following the formula n=pq*q where p is a squarefree number. However, for some ...