Posts

Showing posts with the label vector

C++ vector not storing class

C++ vector not storing class I am writing a simple feed-forward neural network in c++, however when I try to store my neuron class in my layer structure, it crashes and gives this output: terminate called after throwing an instance of 'std::bad_array_new_length' terminate called after throwing an instance of 'std::bad_array_new_length' what(): std::bad_array_new_length what(): std::bad_array_new_length This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. Here is my program: #include <iostream> #include <random> #include <vector> using namespace std; random_device e; int randomG(int min, int max){ return (e()%(max-min))+min; } int f(int v){ return v+5; } class neuron{ public: neuron(int _insN, int _funt...

Sorting a vector of vectors by multiple elements in Julia

Sorting a vector of vectors by multiple elements in Julia I've had good read of the 'Sorting Functions' section of the Julia manual, and had a look at some of the similar questions that have already been asked on this board, but I don't think I've quite found the answer to my question. Apologies if I've missed something. Essentially I have a vector of vectors, with the enclosed vectors containing integers. For the purposes of the example, each enclosed vector contains 3 integers, but it could be any number. I want to sort the enclosed vectors by the first element, then by the second element, then by the third element etc. Let's start with the vector: v = [[3, 6, 1], [2, 2, 6], [1, 5, 9], [2, 1, 8], [3, 7, 9], [1, 1, 2], [2, 2, 2], [3, 6, 2], [1, 2, 5], [1, 5, 6], [3, 7, 4], [2, 1, 4], [2, 2, 1], [3, 1, 2], [1, 2, 8]] And continue with what I'm actually looking for: v = [[1, 1, 2], [1, 2, 5], [1, 2, 8], [1, 5, 6], [1, 5, 9], [2, 1, 4], [2, 1, ...

How to split vector according to indices given in another vector?

How to split vector according to indices given in another vector? I have a source std::vector<double> , which I'd like to split according to indices contained in std::vector<int> . The split is inclusive, and start of next slice should start where previous left off, starting from start of the source vector. std::vector<double> std::vector<int> For example: { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9 } -> source {2, 4, 7 } -> split indices and after applying the function it should produce: {1.1, 2.2, 3.3} {4.4, 5.5} {6.6, 7.7, 8.8} I have this which won't give me the third vector and so on: vector<double> nets{ 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9 }; vector<int> ends{2, 4, 7 }; vector<vector<double>> periodnumbers; vector<double> numbers; for (int i = 0; i < nets.size(); i++) { double temp; temp = nets[i]; numbers.push_back(temp); for (int j = 0; j < ends.size(); j++) { if (i ...