This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Best way of finding max value index for each row in matrix?

Tags: None
(comma "," separated)
parmeet
Registered Member
Posts
9
Karma
0
OS
Hi All,

I want to find maximum value column for each row in matrix. I am doing it using for loop over the rows as shows below in code. I am wondering if there is better way of doing it, more precisely without using for loop. Also is maxcoeff vectorized?

Code: Select all
MatrixXf::Index   maxIndex;
MatrixXf m_sumik(nbSample_,nbCol_);
 for (int i = 0; i < nbSample_; ++i) {
        m_sumik.row(i).maxCoeff(&maxIndex);
        // further use of maxIndex
 }


Thanks for your answers,
Parmeet
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
There is no shorter way yet. Regarding vectorization, vec.maxCoeff() is vectorized (standard reduction), but not the version returning the index: vec.maxCoeff(int&). It's not impossible but I'd not expect significant gain if any.


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell, Yahoo [Bot]