# LaVOZs

The World’s Largest Online Community for Developers

'; Newest 'vector' Questions - LavOzs.Com

# 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.

• ### How do I properly use a switch statement to collect error count?

I'm pretty new to programming and I'm trying to use a switch statement to collect and increment my error count by type. Then I try to collect the messages using a string vector but i'm receiving an ...
• ### How to apply binary search for searching points/pairs in c++?

I want to search if the pair exists in the vector of pairs using binary search. Here is my code: This code is only looking for the first value in pair: Could you modify this code that it will be ...
• ### Numpy: Generating OR intersections between two True/False vectors

I am trying to "combine" two vectors containing true and false values. If i have a vector of 4 (rows) and and second one of 3 (columns, I want to create a 4x3 matrix where the values are an "OR" ...
• ### Covert positive element to negative in vector?

I would like to know how to convert a positive element to a negative one. So for example I have a vector which contains 1,2,3,4,5. How would I convert the 4 to minus 4. int main() { vector <int&...
• ### Threads are running but neither one is accessing the given vector and adding/removing from it

Sorry in advance if this is a stupid question and I've forgotten some fundamental basic knowledge. I've created a project to tackle the consumer/producer problem using threads. I am using a vector as ...
• ### How to input integers into a vector<int> that is empty?

#include <iostream> #include <vector> int main(void) { std::vector<int> ivec; int n = 4; for (std::vector<int>::iterator iter = ivec.begin(); iter != ivec.begin() +...
• ### Using constraints and concept to allow only multi dimensional vector iterators as parameters -std=c++20

I am trying to set requirements for function's parameter to be a multi dimensional vector iterator. For starter I tried setting the multi dimensional vector as the requirement. That is std::vector&...
• ### Is it possible to change the begin position of a vector in C++ to clear its first n elements?

Say I have a vector of integers [1,2,3,4,5,6,7]. As far as I always understood the vector has a memory adress @v and then if we want to access an element i we just need to do @v+i*size_of_element. ...
• ### Reversing a vector in CPP using recursion [closed]

How should we reverse a vector without using inbuilt STL reverse function? The function defenition is as follows. void reverseString(vector<char>& s) We must do it in-place i.e. O(1) ...
• ### Do I have to manually iterate vector of tuples to find a single value? [duplicate]

Say I have a vector holding many std::tuple<std::wstring, void*> values. All the std::wstring values and the void* values are unique to each other in the vector. My function is trying to locate ...
• ### Cause of data corruption in C++ vector?

I'm trying to write a basic MP3 player to try and get into some Windows stuff for C++, and things were going well until now. I tried writing a queuing class to play more songs after the current one ...
• ### What is the correct syntax to fill a String vector that is inside an Object vector? In Java

Language is an attribute of Project (Object Vector) Project is instantiated as p. Proyecto p[] = {new Proyecto(0, null, 0, null, 0, 0)}; p[x].setLanguage("¿Position and value? ¿How?");``` //The ...
• ### C++ how do i override the << operator within a class

How would i override the << operator within a class? Or be able to print a vector<byte> from within a class. My current code looks like ostream& operator<<(ostream& os, ...
• ### calculating a new look-at position

Context: I'm learning the Go language and using a Go OpenGL library that implements Go bindings over OpenGL. I'm porting something that I wrote in Java and JMonkey. JMonkey has a fly camera that ...
• ### Reading text file and make the column as vectors

For example, I have a text file name example.txt. It has two columns. 12561 60295 13561 60297 13561 60298 13461 60299 15561 60300 15161 60301 15561 60302 14561 60316 12561 60317 ...
• ### Why does my program not show me the position of the element in the vector? [closed]

I'm new to std::vector, and I don't know why my C++ program doesn't show me the index of the max digit of a number. For example, if I put 1 and the number is 123, it should show me 2, cause "2" is the ...
• ### Rotating a 2D vector by small angle - clockwise and counterclockwise

I need to create a rotation for 2D vector by a small angle ( about 0.01 radians). I need to do this in both directions. So that in the end I have the starting vector and two identical vectors on each ...
• ### Having an error code C2676 with an iterator to a vector of customtype [duplicate]

vector<element>::iterator it; it = find(table.begin(), table.end(), temp->c); if (it != table.end()) { table.push_back(*temp); } That's where the error occurs struct element { char ...
• ### how to declare and fill a vector of objects inside another vector of objects in java?

How to declare and fill a vector of objects inside another vector of objects? Also... How to declare and fill a String vector inside another object vector? For example: I have a vector of objects (...
• ### invalid use of incomplete type 'class …' STL vector

I have some questions with the definition of a class inheriting STL vector. This class is suppost to publicly inherit from std::vector, but I keep getting the following error from the compiter. I am ...
• ### How can I tell if my vector matches the variable values in r?

I am new to r. I am having trouble understanding if my code is accurate. Essentially, I have assigned a dummy variable 'edu.degree.level' to an existing variable in the data frame. The original ...
• ### Vector has the same size out of function that uses push_back() [duplicate]

I have a program for school to make and i thought i'd use vectors, everything went smoothly but at the end I saw that function in my program that pushes elements to vector of classes do it only inside ...
• ### Is there a way of working in spherical coordinates in SymPy?

I am working in a script to do analytical calculations in Python. For it I would need vector representation of my parameters and also some basic vector operations such as Gradient and Divergence, and ...
• ### How to insert a new element at the beginning of std::vector without any copy and default constructing overhead if I know the number of elements?

I need to fill from end some preallocated uninitialized memory region. I want to use std::vector, but I don't want inserting each new element at the beginning of vector forcing it to make unnecessary ...
• ### How to read binary file into vector<bytes>? [closed]

File consists of unsigned integer value that represents length of the rest of the file, followed by the rest of the bytes ( if there are 100 bytes that have to be added to a vector, file data will ...
• ### Vector rotation in 3D

I have two points, A and B, in 3D space, and I know the magnitude and direction of vector AB (in x,y,z coordinates). I have a force F at A, and I know its magnitude and direction. I can resolve this ...
• ### Eigen::Vector template class?

If I want to statically allocate a vector using the Eigen library I can simply use Eigen::Matrix<double, kNumStates, 1> vec; but I can't seem to find something of the form Eigen::Vector<...
• ### How could I assign values to c++ vector

I know that I can initialize a vector like this: vector<int> v{1,3,4,6}; However, when I define a class which contains a vector, I cannot initialize it in the position that I declare it, like ...
• ### Is there any simple way of taking integer inputs from user to fill up a vector and also provide an option to stop in C++?

I need a block of code that takes input from user as long as he wishes and fill up a vector with it. I got stuck at providing some stop mechanism by which user can inform the end of inputs. I tried to ...
• ### realloc vs memcpy in dynamic array like vector in C

I was using a data structure vector in C. Like this struct intVector { int* head; size_t capacity; size_t size; }; When implementing pushIntVector function, I have two options when the array'...
• ### Cross validation of Time Series data: VAR model

I have weekly data with 15 predictor variables for a period of 1 year (52 observations). I plan to compare Prophet forecasting with VAR model. Is there a way to run cross-validation for these 2 ...
• ### How to test that range values are contained in any of another range values in MATLAB?

I am trying to check if in two vectors having multiple entries containing pair of ranges, whether a range from one vector is part of another range? I have one test range vector, which contain pair of ...
• ### Don't understand vector C++ [duplicate]

#include <iostream> #include <vector> using namespace std; void SaveNumbers(vector<int> numbers); int main() { vector<int> numbers; SaveNumbers(numbers); cout &...
• ### C++ How to use vector class to create collection

How i can use vector class to create collection? I have to create collection of people's using vector class. I've tried these, but how i can "push_back" a variable? using namespace std; int main() { ...
• ### Segmentation fault cpp using vector of vectors

I'm having a segmentation fault that I can't understand what is the exact problem. I'm iterating over some folders that each folder have some files that i get a data from and construct an objects from ...
• ### Singleton vector different from its transpose in Julia

If I define A = [1] I get that A is not equal to A' since they are of different types: julia> A=[1] 1-element Array{Int64,1}: 1 julia> A' 1×1 LinearAlgebra.Adjoint{Int64,Array{Int64,1}}: 1 ...
• ### Sorting a vector by unordered map of the elements pointers as keys

I have a vector of elements std::vector<T> my_vec. At some point in my code I assign a score for each element of the vector using an unordered map. After that, I would like to sort the vector by ...
• ### Python Numpy matrix multiplication with vector convergence loop

I need to write a code in python using numpy to iterate and loop through to multiply it a matrix by a new vector 72 times. Any help will be appreciated. The matrix is shown as P and the vector is pop....
• ### Read every line from text file to a vector C++

I have a text file where I need to be able to add or delete certain lines using functions. Everything is read from the file so when I open the file and write something then it deletes everything else ...
• ### R: How to interpolate a string variable into a vector [duplicate]

i am having trouble to use custom strings in a vector, like this: myString = "bar" anotherString = "foo" foo <- c(myString = 1, anotherString = 2,) foo ❌ Output: myString anotherString 1 ...
• ### Is clearing a vector of a class containg vector enough to clear everything?

Let's consider a class that contains a vector: AGivenClass { public: vector< int > vec_int; }; and let's consider that we have an instance, which is a vector of the class : vector < ...
• ### (C++) Problems with saving vector into .txt database

So I have a .txt database where I store player data. Each line represents a new player. For example, if I create 2 players, the file should look like this. PlayerID 0|Name|Biography|0|0|0|0|0|0 ...
• ### How to get the index of an element in a vector of variants?

From a vector<variant<T1,T2>> vec I have a T1& elem that is known to be in vec. I want to find the index i such that get<T1>(vec[i]) is elem. But I'm not sure if this is legal: ...
• ### How to convert vector back to Sentence using TensorFlow's Universal Sentence Encoder?

I'm using TensorFlow's Universal Sentence Encoder and I want to convert a generated vector back into a sentence. TensorFlow provides a way to go from a sentence to a vector, but I want to reverse this....
• ### Counting the appearance of words in a vector and listing those in a list, C++

I have a cpp vector containing separate words and I need to count how many times a word appears using a list. I try to iterate through the list but failing with the comparison of the two STL ...
• ### Copy one element from a vector to another vector

Hi I would like to know how to copy one element chosen from one vector to another. So for example I have two vectors. I would want to copy the number 7 from v1 to v2 using the position of the element. ...
• ### vector::_M_range_check: __n (which is 1886417008) >= this->size() (which is 256)

This function helps visualize the Y, U, and V channels of the input image. input_image is the YUV input image, u_colormap is the map to visualize the u channel, and v_colormap is the map to visualize ...
• ### Subset vector: remove one element, based on value rather than position

library(tidyverse) view first 15 records in starwars dataset head(starwars, 15) remove the 10th record ("Obi-Wan Kenobi"), based on position in the vector "Obi-Wan Kenobi" is in the 10th ...
• ### `int size() const` or `const int size()` [duplicate]

I am working on an implementation of a simple Vector class that forms a container for a constant sized double array (following the example on page 51 of A Tour of C++). My issue is with the method int ...
• ### How do I add a vector onto an NMDS in R?

I am trying to work out if Salinity has any effect on invertebrate community structure. I've managed to make my NMDS but every time I try ordiplot or envfit there are errors with unsuitable data type. ...