Find min/max in a two dimensional array

Here’s one way to get the min and max values: $min = min(array_column($array, ‘Price’)); $max = max(array_column($array, ‘Price’)); To return the nested array for the min and max: $prices = array_column($array, ‘Price’); $min_array = $array[array_search(min($prices), $prices)]; $max_array = $array[array_search(max($prices), $prices)]; You could do each in one line since that looked like what you were trying … 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

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)

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