Return max repeated item in list

Not the absolutely most efficient, but it works: var maxRepeatedItem = prod.GroupBy(x => x) .OrderByDescending(x => x.Count()) .First().Key; This is more efficient: var maxRepeatedItem = prod.GroupBy(x => x) .MaxBy(x => x.Count()) .First().Key; but it requires MoreLinq‘s extension MaxBy EDIT (as per comment) : If you want all the max repeated elements in case of ties, … Read more

How can I get the maximum or minimum value in a vector?

Using C++11/C++0x compile flags, you can auto it = max_element(std::begin(cloud), std::end(cloud)); // C++11 Otherwise, write your own: template <typename T, size_t N> const T* mybegin(const T (&a)[N]) { return a; } template <typename T, size_t N> const T* myend (const T (&a)[N]) { return a+N; } See it live at http://ideone.com/aDkhW: #include <iostream> #include <algorithm> … Read more

Max in a sliding window in NumPy array

Pandas has a rolling method for both Series and DataFrames, and that could be of use here: import pandas as pd lst = [6,4,8,7,1,4,3,5,7,8,4,6,2,1,3,5,6,3,4,7,1,9,4,3,2] lst1 = pd.Series(lst).rolling(5).max().dropna().tolist() # [8.0, 8.0, 8.0, 7.0, 7.0, 8.0, 8.0, 8.0, 8.0, 8.0, 6.0, 6.0, 6.0, 6.0, 6.0, 7.0, 7.0, 9.0, 9.0, 9.0, 9.0] For consistency, you can coerce each … Read more