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

Find the second largest element in VectorXd

Tags: None
(comma "," separated)
marvisiyer
Registered Member
Posts
21
Karma
0
I would like to find the second largest element and in general the k^{th} largest element in VectorXd. Currently, I am aware that if 'A' is of type 'VectorXd', then
Code: Select all
s = A.maxCoeff(&r)
stores the maximum value in s and the corresponding index in r.

Thanks
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
You can use std::nth_element on a copy of the vector using vec.data() and vec.data()+vec.size() as begin/end iterators.
http://en.cppreference.com/w/cpp/algorithm/nth_element


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]