c++ - fill a mulit-dimentional matrix with uniformly distributed random numbers with diffierent ranges -


i want fill 10000x2 matrix in opencv (v3.2) random numbers in uniform distribution different ranges each column , here problem following code:

mat centers(10000, 2, cv_32f); rng rng(time(null)); rng.fill(centers, rng::uniform, scalar(0, 0), scalar(10, 1000)); 

i expect first column randomly filled values between 0 , 10 , second column filled values between 0 , 1000. both columns filled values between 0 , 10, decided implemented in following form.

mat centers(10000, 2, cv_32f); rng rng(time(null)); rng.fill(centers.colrange(0, 1), rng::uniform, 0, 10); rng.fill(centers.colrange(1, 2), rng::uniform, 0, 1000); 

but not work either. think because rng::fill not support noncontinuous matrices (which not mentioned in documentation) remaining way use loop waste of time , performance. doing sth wrong above or should give , use loop

you have misinterpreted api documentation of rng::fill(), defines parameters , b as:

a - first distribution parameter; in case of uniform distribution, inclusive lower boundary.

b - second distribution parameter; in case of uniform distribution, non-inclusive upper boundary.

so there no mention in documentation can pass multiple ranges in a , b. solution create 2 mat of 1000 x 1 dimensions, use different values of a , b both of them , later join both of them create unified mat 1000 x 2 dimension.

cv::rng rng = cv::rng(0xffffffff); cv::mat centers(10000, 1, cv_32f); cv::mat centers2(10000, 1, cv_32f); rng.fill(centers, cv::rng::uniform, cv::scalar(0), cv::scalar(10)); rng.fill(centers2, cv::rng::uniform, cv::scalar(0), cv::scalar(1000));  cv::mat final; cv::hconcat(centers, centers2, final); 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -