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

Find min, max, and average of a list

from __future__ import division somelist = [1,12,2,53,23,6,17] max_value = max(somelist) min_value = min(somelist) avg_value = 0 if len(somelist) == 0 else sum(somelist)/len(somelist) If you want to manually find the minimum as a function: somelist = [1,12,2,53,23,6,17] def my_min_function(somelist): min_value = None for value in somelist: if not min_value: min_value = value elif value < min_value: … Read more

Use of min and max functions in C++

fmin and fmax are specifically for use with floating point numbers (hence the “f”). If you use it for ints, you may suffer performance or precision losses due to conversion, function call overhead, etc. depending on your compiler/platform. std::min and std::max are template functions (defined in header <algorithm>) which work on any type with a … Read more

min for each row in a data frame

You can use apply to go through each row apply(df, 1, FUN = min) Where 1 means to apply FUN to each row of df, 2 would mean to apply FUN to columns. To remove missing values, use: apply(df, 1, FUN = min, na.rm = TRUE)