c++ vector of vectors size of the next column - c++

I am writing a code to do some template matching using cv::matchTemplate but I have run into some problems with the 2-dimensional vector of vectors (vov) I created which I have called vvABC. At the moment, my vov has 10 elements which can change based on the values I pass while running the code.
My problem is moving from one column in my vov to the next so I can calculate the size. From my understanding of how vov works, if I have my elements stored in my vov as:
C_A C_B
0 0
1 1
2 2
3
4
5
6
To calculate the size of the first column, I should simply do something like:
vvABC[0].size() to get the size of the first column (which would give 3 in this case) and vvABC[1].size() to get the size of the second column (which would give 7). The problem I am now faced with is both of them give '3' in both cases which is obviously wrong.
Can someone please help me out on how I can get the correct size of the next column?
I stored my detections in my vvABC, now I want to match them one at a time.

It seems like you made a mistake here:
for (uint iCaTemplate = iCa + 1; iCaTemplate < vvABC[iCa].size(); ++iCaTemplate) {
iCa is an index on the 'first level' of vector (of size 2 in your example above), i.e. columns, and you use it to go through the elements of the 'second level' of vector, i.e. rows.

Thanks a lot guys, esp. JGab, after several debug outputs, I finally found that my vector of vectors wasn't being filled up the way I thought it was...thanks once more and my apologies for my belated response.

Related

Starting an element at certain coloumn within Susy grid

What the best way to position an element say 2 columns in. Is there a short hand syntax like
span (6 at 2)
Which i've tried but doesn't work.
Or is the correct way to apply a left margin. Also can you get the span count to start from the right?
Thanks
span (6 at 2) works if you are using output: isolate — because isolation calculates position from the left edge for all elements. With the standard float output, you have to push or pull elements where you want them. Those push and pull the element from their default place in the flow (using margins).
#include span(6);
#inlude push(2);

how to calculate nth term of mth row of this table?

there is a table which grows as
1,1
1,1,2
1,1,3,3
1,1,4,4,6
1,1,5,5,10,10
1,1,6,6,15,15,20
.....and so on
If i want to find an specific element of the table like if I want to find 4th element of 6th row then the answer will be 6 but if I want to find the nth element of mth row for any n>=1 m>=1 then how to do it?
These numbers look like binomial coefficients, so this "table" could be Pascal's triangle row-wise re-ordered by size.
Though, this is just one of the infinitely many "tables" that'd start like this. If you don't name a specific production rule or another way to deduce arbitrary values of the "table", there's no way telling for sure which of those infinitely many "tables" you have here.
I assume you want to hold the values in a kind of table without wasting memory by for example giving each line more slots than necessary.
To do that I'd suggest a vector of vectors (assuming your values are integers):
std::vector< std::vector<int> > table;
Provided you are sure that a value at (m, n) exists you can get it with:
int value = table[m][n];
(Note that m and n count from 0.)
If you're not sure use the safer
int value = table.at(m).at(n);
which will throw an exception if (m, n) doesn't exist.
To add a row you could call
table.resize(table.size() + 1);
and to add a column to a row
table[m].resize(table[m].size() + 1);
I'd recommend to put the table into the protected or private section of a special class and add functions to access the elements as needed.

Data structure for storing unique values

I need to keep data of the following form:
(a,b,1),
(c,d,2),
(e,f,3),
(g,h,4),
(i,j,5),
(k,l,6),
(m,a,7)
...
such that the integers within the data (3rd column) are consecutively ordered and are unique. Also there are 2,954,208,208 such rows. I am searching for a data structure which returns the value of the 3rd column given the value of first two columns e.g.
Given: (i,j) it returns 5
And given the value of 3rd column, first two columns can be retrieved. For example,
Given: 5 it returns (a,b)
Is there some data structure which may help me achieve the same.
My approach towards solving this problem was to use hash-maps..but hash-maps do not turn out to be efficient. Is there some other way out.
The values in the first, second and third column are all of 64-bit.
I have 4GB of RAM.

call to column gives row vector instead of column vector python

Hey im making a loop where I have to repeatedly update a column vector X estimate by adding another column to the X estimate, however whenever i'm calling a Column in this x estimate it givers me a row vector and I Cannot redefine the output row as a column using vstack because then I will no longer be able to plug it in at the start of the loop where it is needed for new calculations
Below the output for my xestimate
Xest = [[ 0. 0. ]
[ 1. 1. ]
[ 1. 1.0001]
[ 1. 1.0001]]
later on the call 'Xest[:,0]'
output >> '[0 1 1 1]'
however i need it to be a column,
'[[0], [1], [1 [1]]'
I dont really understand with the call [:,0] it should be a column should it not?
Thanks
I understand Xest is a numpy array.
Quick answer:
You can obtain what you want with np.vstack(Xest[:,0]) or, better, Xest[:,0][:, np.newaxis]
Slightly longer answer:
Why do you want to do that? Most of the time, you don't, and just rely on broadcasting to do it for you. There is no such a thing as "column vector" in numpy, so most cases can be handled with a normal "row vector". For those corner cases where you do need a distinction, you can make a view and play with the strides, as [:, np.newaxis] does.
Full justification:
Imagine you have an array of 10 dimensions, and you want one vector. Do you really want an array that is like [[[[[[[[[[1, 1, 1, 1 ...]]]]]]]]]]? Numpy is meant to work with arbitrary dimensions, and therefore, designed for the general case.

power function and arrays in c++

I'm trying to write a function that will take an array or vector and have its values taken to a "power of" and then display it's values. I'm not too familiar with arrays but simply put I'm trying to create something like
n = {2^1, 3^1, 5^1,2^2,3^2,5^2,....}
the "power of" is going to be looped.
I then plan to sort the array, and display 1500th term.
this problem corresponds to prime number sequence only divisible by 2 , 3 & 5;
I'm trying to find a more time efficient way than just if statements and mod operators.
If I remember correctly this is the Ugly Numbers problem I've faced some years ago in the UVa.
The idea to solve this problem is to use a priority queue with the numbers 2, 3 and 5 as initial values. At each step remove the topmost value t and insert the values 2*t, 3*t and 5*t in the priority queue, repeat this steps till the 1500th term is found.
See this forum for more info: http://online-judge.uva.es/board/viewtopic.php?t=93