Questions tagged [vector]

1

votes
3

answer
1.1k

Views

Convert std::vector<uint8_t> to QImage

I am trying to create QImage from std::vector. I tried; void FaceCutThread::convertImage(std::vector &buf) { QImage img(&buf[0], 300, 300, QImage::Format_ARGB32); emit isFinisedFaceCut(img); } and void FaceCutThread::convertImage(std::vector &buf) { QImage img(buf.data(), 300, 300, QImage::Format_...
goGud
0

votes
0

answer
17

Views

How to create a vector using elements greater than x in another vector

I created aVector containing 100 random values between 0 and 100. Now I need to create bVector by pulling whole elements from aVector that are >50. Can I use runif? I've tried using runif placing aVector within the function but it's pulling fractioned numbers between 51 and 100. set.seed myVector
Conner M
1

votes
1

answer
108

Views

Haskell vector type declaration

I'm writing a comparator to pass to sortBy but I can't get the type declaration right. The input is two Data.Vector's, each containing two numbers. -- Comparator to sort a list of individuals by increasing order of fit-0 -- and for individuals with equal fit-0, with increasing order of fit-1 i...
tsorn
0

votes
1

answer
42

Views

Vector.push_back() adds same Element while reading from File

My Code is reading a set of Elements from a file and adds those to a Vector. The for-loop reads all the elements and via push_back they are added to the vector. Works perfectly fine on paper BUT: In the end all the Elements in the Vector are equal and always the last read element. I am 100 percent...
jakob
1

votes
2

answer
14

Views

R: subset of character vector

I want to get a subset from a character vector. However I want to obtain vector2 containing elements from initial vector between specific elements. vector
Mikołaj
2

votes
1

answer
13

Views

Why is my F# vector add function using tail recursion not working?

I cannot get this to work in F#. I am trying to write a tail recursive form of vector add and pass the previously calculated values using a. It is giving error "error FS0001: Type mismatch. Expecting a ''a' but given a ''b list -> 'c list -> 'a list' The types ''a' and ''b list -> 'c list -> 'a li...
qscott86
1

votes
5

answer
69

Views

How to lag a vector then create a matrix?

I'm plan to write a function called lagit(a,k) to get a result like this: lagit(c(1,5,6,4,7),c(1,3)) then it should output: L0 L1 L3 1 NA NA 5 1 NA 6 5 NA 4 6 1 7 4 5 I'm facing 2 problems right now: 1. lag each column as each element in vector k; 2. how to bind a vector to a matrix(I used...
Ruitao Zhang
1

votes
0

answer
7

Views

Adding a shadow effect to a vector drawable

I want to add shadow effect (or elevation) to the vector drawable. for example 1.My first file contains a download icon in ic_file_download_black_24dp.xml 2.My second file contains a round shape in round_shape.xml 3.Now, I'm combining these two files to create single layered-drawable like this whic...
Jay Patel
1

votes
2

answer
256

Views

Clojure - Idiomatic Way To Fill A Vector While In A Loop

I have a requirement where upon receipt of a request, I have to fetch values from an external source, filter them and return the filtered values to the caller. I am accumulating the result (until it reaches the required size) by fetching a specified amount of records from the external source at a ti...
Mohamed
1

votes
2

answer
1.5k

Views

Count frequency of each element in vector

I'm looking for a way to count the frequency of each element in a vector. ex
1

votes
2

answer
609

Views

R: Name a data.frame after a value in a vector

I am trying to create a data.frame within a for loop. I want to name the data.frame after whatever the value is in the vector for that iteration of the loop. The vector comes from the City column in the State data.frame: State City Zip A 1 B 2 C 3 What I have tried: for( i in State$C...
Dre
1

votes
2

answer
117

Views

Set specific vector elements to NA in R

I am trying to solve an excercise for my R online course. We have a vector B: B
Rio
1

votes
1

answer
152

Views

android:pivotY doesnt add top-padding to my android vector drawable

I have compactTextView with compoundDrawable. I want to add top padding to that compoundDrawable which is fed by vector image (I imported svg into android studio) I saw this post on how to add padding to a vector drawable but when i try this, no padding is added: do I need to add anything else?
Elad Benda
1

votes
1

answer
36

Views

How do I set a Three.js Plane rotation with an Object3D's local rotation?

I have a Plane, and a Group of objects, which has a rotation. I need to set the plane's surface normal to always be rotated in accordance with the Group's rotation (this rotation changes based on user input). I've tried things like this, which sort of work: onGroupRotation() { const vec = orbitGroup...
nnyby
1

votes
0

answer
10

Views

Expected input to torch Embedding layer with pre_trained vectors from gensim

I would like to use pre-trained embeddings in my neural network architecture. The pre-trained embeddings are trained by gensim. I found this informative answer which indicates that we can load pre_trained models like so: import gensim from torch import nn model = gensim.models.KeyedVectors.load_word...
Bram Vanroy
-2

votes
0

answer
19

Views

How do I copy elements which are stored in a int list to a int vector? [on hold]

I have a task to copy a listx elements into vectory using STL algorithms. I have checked everywhere, seems there is no way. Does anyone know? Please help out. I have created another vector with capacity to copy up to 10 elements. But my copy() function is not working. /*Here is the chunk of a code...
Chora Mora
1

votes
1

answer
1.1k

Views

vector resize doesn't work? [closed]

I have 3 maps with a string as key and a vector as value. std::map m_attri; ///< Attributes of type int std::map m_attrd; ///< Attributes of type double std::map m_attrs; ///< Attributes of type std::string I have a function that resizes them all, calles SetNum() void SetNum(si...
Pinna_be
0

votes
3

answer
29

Views

C++: Vector subscript out of range when trying to fill multiple vectors with getlline() in a single for loop

When I try to run this code: vector names; vector telephones; vector emails; for (int i = 0; i < 5;i++) { cout
Ajtsh
1

votes
1

answer
1.4k

Views

Merging two sorted vectors in one sorted vector

Background: General Goal take two sorted files with strings separated by white space, and bring them together in to one sorted file. Current Goal, to see if i can use the merge function or a similar function to combine two sorted vectors. I was using http://www.cplusplus.com/reference/algorithm/mer...
1

votes
2

answer
3.6k

Views

Numbers in initialization vector (IV) are all zeros

I'm having trouble understanding the following sentence : "the numbers in initialization vector (IV) are all zeros (not the ASCII character '0'). My goal is to use openssl enc command to encrypt a file using aes-128-cbc with a key K (let's say 1234567890) and the iv that fulfil such requirements. So...
JaneDoe
1

votes
1

answer
61

Views

how to create a vector as an argument [closed]

I have an object that takes a vector as one of it's constructor arguments. I will have around 1000 of these objects (contained in a vector) in each of 12 files by the time I'm finished, and I've been experimenting with layout. The best way I can find to work it is to create all arguments within the...
Iron Attorney
1

votes
4

answer
117

Views

Optimizing vector assignment c++

I have a function which returns a vector. Let's name it v. I use v.begin() and v.end() in a function. How could I make using .begin() and .end() without creation a new vector v2 to store the previous vector v so I can get access to methods? Here's what I mean: std::vector merge(...) { ... return v;...
Val Baturin
1

votes
3

answer
1.4k

Views

Sorting Vectors Of Shared Pointers in C++

Let's say we have a simple class as such: class Data { private: std::string m_name; unsigned m_id; Data( const std::string& name, unsigned id ) : m_name( name ), m_id( id ) {} void setName( const std::string& name ) { m_name = name; } void setId( unsigned id ) { m_id = id; } std::string getName() co...
Francis Cugler
1

votes
1

answer
1.7k

Views

Check whether std::vector<bool> is comprised of only true values

What is the fastest way to determine whether a vector holding boolean values (which is typically optimized as a bit array) only holds true values? For small vectors, I think it might not be a bad idea to just compare the vector against another vector storing only true values (assuming we know the si...
AnimatedRNG
1

votes
2

answer
2.6k

Views

Extract variable names from list or vector in R

Assuming: aa = c('A','B','C') bb = c('D','E','F') list1 = list(aa,bb) vect1 = c(aa,bb) Is there a way to extract the variable names as strings ('aa', 'bb') from either list1 or vect1? Is this information being stored in lists and vectors? If not, what would be the appropriate format? Thanks in adva...
Daan11
0

votes
0

answer
5

Views

How to get resized image from PDF vector asset?

I am developing game with SpriteKit for iPhone devices only. In the scene I have buttons, which need to be positioned in the way to feel the height of the screen: There should be no gaps between top and bottom edges, as well as from each other. The width can vary. In order to achieve that, I though...
Pablo
1

votes
2

answer
244

Views

How to implement large vector initialization that compiles with gcc-4.4?

I have a list of 20k known strings that I know at compile time and will never change. A sort of non-configurable dictionary. I do not want to load it in run time from a file, because this would imply a lot of unnecessary architecture: finding the file in a certain path, a configuration file to indic...
Jordi Adell
1

votes
1

answer
362

Views

Windbg c++ how to print vector contents

I have the below code snippet Class Filters { vector numbers; } Filters f1; I need to debug the content inside f1.numbers Windbg> ??f1.numbers class std::vector +0x000 _Myvec : std::vector +0x018 _Mysize : 7 Windbg> ??f1.numbers._Myvec._Mypair._Myval2 class std::_Vector_val +0x...
aravind
1

votes
2

answer
163

Views

How to subtract the intersection of UIBezierPath A&B from A?

Suppose we have two UIBezierPaths, path1 and path2... (that have already been defined relative to view bounds at runtime and already exist as properties of the same view). We want to get a new path of type UIBezierPath, path3, that is the result of subtracting path2 from path1: The way this is done...
Boober Bunz
1

votes
2

answer
131

Views

In C++ is there any way to apply a function 'simultaneously' to all the elements of a vector ?

I have a vector of length 6, with elements either 1 or zero. I want to apply 'XOR' on 2 elements on both sides of every ith element. e.g. for i = 1, I'll apply xor on 0th and 2nd element. the ith element is then replaced by this xor output. I want to apply xor for all such 'i's simultaneously on the...
user4152296
1

votes
2

answer
52

Views

Adding elements to std::vector in a repeated way

I want to copy values from one vector to other one that will be stored in a specific order and the second vector will contain more elements than the first one. For example: vector temp; temp.push_back(2); temp.push_back(0); temp.push_back(1); int size1 = temp.size(); int size2 = 4; vector temp2(size...
Montezuman
1

votes
2

answer
25

Views

Get index of element in unfiltered vector

I have a rle object from a vector and would like to get the sum of lengths (with values == TRUE & values == FALSE) before and after the maximum of lengths (with values == TRUE) That I can do: se
yasel
1

votes
2

answer
83

Views

Removing unique_ptr´s from a Vector and using them as parameters for new Struct

The syntax of moving std::unique_ptr() somewhat eludes me, and i can't find a clear answer(to me at least), as to how i should move the unique_ptr around. I have some heap-allocated Nodes and would like to create new Nodes, which have two already existing Nodes as children. Which in turn are suppose...
Clebo Sevic
2

votes
1

answer
23

Views

How to get the elements of a System.Numerics.Vector in C#?

I want to access the elements of a System.Numerics.Vector in C#. I'm following the official documentation: https://docs.microsoft.com/en-us/dotnet/api/system.numerics.vector-1?view=netcore-2.2 I'm able to create different vectors with different datatypes. For example: var test = new Vector(new doubl...
Marcel Gangwisch
-3

votes
0

answer
48

Views

Sorting Vector of pairs is unstable C++

How to implement insertion sort if I want to sort vector of pairs according to the first element and I want that elements wchich are equal in sorted order first will be this which first appeared.Maybe insertion sort is ont good to this? void sort(){ pair el; int j; for(int i = 1; i < biezacy; i++){...
Kamil Stpniewski
1

votes
1

answer
267

Views

Function Pointer as Function Parameter

I've been writing a utility to work as a wrapper for GLFW Key Input. I wanted to have a set of functions that would enable me to easily pass the key code and the function I wanted to be triggered upon the key being pressed or released. I think everything here is right but I'm attempting to use it in...
Joshua Barnett
1

votes
2

answer
629

Views

C++ Error on vector of objects containing threaded function

do you know of any method (C++) to create a vector of objects containing a threaded function? Ideally the technique has to be crossplatform (Win/OSX) and easily portable to mobile (iOS). It can be very basic multithreading, the function to be run in parallel is pretty simple (but computationally int...
mαττjαĸøb
1

votes
2

answer
844

Views

vector initialization in vs2010

#include #include #include using namespace std; class M { vector s; public: M(){ s = {"abc", "abc", "abc", "abc", "abc"}; } }; int main(){ return 0; } The code can be compiled in c9, but in vs2010, it can't be compiled successfully.why?
user2793559

View additional questions