Questions tagged [max]

Maximum value. Largest, biggest, greatest.

max

max() is a math library function available in many programming environments which returns the entity of greatest value from two or more candidate values.

Do not use for questions about the maximal value of a type, e.g. Long.MAX_VALUE, Integer.MAX_VALUE, etc.

Examples

SQL

SQL MAX() function is one of aggregate functions. It returns the largest value of column.

SELECT MAX(column_name) FROM table_name;

Python

In Python, the native max function identifies the largest element of a set (e.g. a list).

>> max([1, 2, 3])
3

Java

In Java we can use java.lang.Math class to compute maximum value of two arguments.

int maxElement = Math.max(x, y);

To compute maximum element in collection we can use, max() method from java.util.Collections class.

int maxElement = Collections.max(list);

Ruby

In Ruby to compute maximum element of collection we simply use max function.

[4,7].max

Clojure

In Clojure we use max function in the following way.

(max 1 2 3 4)

In above code max is the function name and numbers 1..4 are arguments passed to it. We can also apply the max function to lists.

(apply max [1 2 3 4])

R

In R we have function max.

x <- c(1, 2, 3)
y <- c(4, 5)
z <- c(6, NA)
max(x)
max(y)
max(z)
max(z, na.rm = TRUE)
max(x, y, z, na.rm = TRUE)  ## as same as max(c(x, y, z), na.rm = TRUE)

Rust

In Rust we can use std::cmp::max to compute the maximum value of two arguments.

let max = std::cmp::max(x, y);

We can compute the maximum element in a collection by transforming it into an Iterator and then calling the max method on the iterator.

let max = collection.into_iter().max();
8982 questions
2
votes
1 answer

What is the maximum possible Apache HTTP TimeOut directive?

What is the maximum possible value that Apache2 Web Server allows for it's TimeOut directive in your httpd.conf or apache2.conf (in server config or vhost config) without failing back to the default value? EDIT: To clarify, what I mean by 'failing…
Norr
  • 135
  • 1
  • 8
2
votes
5 answers

How to get the last day of a month on different items? - SQL

Supposed I have some sample data in table_name_a as below: code val_a date ------------------------- 1 00001 500 20191101 2 00001 1000 20191130 3 00002 200 20191101 4 00002 400 20191130 5 00003 200 …
user12336707
2
votes
2 answers

Finding min, max, avg in Pandas, Python for all rows with the same first column

Is it possible to find minimum, maximum and average value of all data with a same first column? For example, for first column 1_204192587: take into account all rows and columns from 4 to n find min, max and avg of all entries in columns 4+ and…
B.Germ
  • 85
  • 1
  • 3
  • 8
2
votes
1 answer

how to sum a list of max values group by

I'm trying to sum the max values of a column named value1 grouped by sensor id value so I want the last greater value from each sensor id. Using this code I get a column with rows with the max results for each sensor. But I dont know how to sum…
2
votes
3 answers

Finding MAX date aggregated by order - Oracle SQL

I have a data orders that looks like this: | Order | Step | Step Complete Date | |:-----:|:----:|:------------------:| | A | 1 | 11/1/2019 | | | 2 | 11/1/2019 | | | 3 | 11/1/2019 | | | 4 |…
artemis
  • 6,857
  • 11
  • 46
  • 99
2
votes
2 answers

Find key based length of values in dict

I have dict like follows: a = {'abc':[0,1,2], 'def':[0,1,2,3,4], 'ghi':[0,1,2,3,4,5]} Want to get the key based on the max length of the array contains. As in here, out put would be 'ghi'. Anybody how to do it. I have tried: lambda x:…
abhi1610
  • 721
  • 13
  • 28
2
votes
1 answer

In numpy, what is the efficient way to find the maximum values and their indices of a 3D ndarray across two axis?

How to find the correlation-peak values and coordinates of a set of 2D cross-correlation functions? Given an 3D ndarray that contains a set of 2D cross-correlation functions. What is the efficient way to find the maximum(peak) values and their…
L. Marval
  • 25
  • 4
2
votes
1 answer

Permutation of euclidean distances between 13 row indexes in R

I have 13 Area of Interests (AOIs) with x and y values for each test image. How can I get all possible combination of euclidian distance between pairs of AOIs, ((x-xi)+(y-yi))^(1/2)? Ultimately I am looking for the maximum distance from all possible…
Hyokstayo
  • 33
  • 3
2
votes
2 answers

Calculate maximum of next 3 rows of a particular column in each row in Python

I have a dataframe like this: seq score 0 TAAGAATTGTTCTCTGTGTATTT -23.19 1 AAGAATTGTTCTCTGTGTATTTC -3.67 2 AGAATTGTTCTCTGTGTATTTCA -16.49 3 GAATTGTTCTCTGTGTATTTCAG -11.83 4 …
rshar
  • 1,381
  • 10
  • 28
2
votes
1 answer

Oracle SQL - Only return value for enquiry ID with the highest enquiry_log_number

I've got some code to return a list of all enquiries where one of the enquiry_status_codes are present from a predetermined list. …
Rob Morris
  • 137
  • 6
2
votes
2 answers

How to retrieve max key and corresponding value from the tuple in the dictionary based on the first argument of the tuple

For example, if the given dictionary is as following: dic = {('K1', 'S1'): 4.999997655759467, ('k1', 'K2'): 6.1999036349232375, ('K1', 'K4'): 7.999999999999876, ('K2', 'K1'): 6.199940422452897, ('K2', 'K3'):…
Leekhamxay
  • 23
  • 3
2
votes
1 answer

YII + beforeSave() + getting max value from a table row

i'm struggling to get my beforesave in Yii Framework working this way: when the user sends the form, beforesave() should fetch the highest number in a column called 'order' and insert a value of order+1 into current 'order' field. After a few hours…
ok_computer
  • 67
  • 1
  • 2
  • 8
2
votes
2 answers

i want to find max node in linked list by recursion algorithrm but my code has problem

if I enter amount of linked list is 3 : x1 = 3, x2= 1, x3=2 that print : 2 1 3(it really true) but max=2, I could not find bug, This is my code: int max(Node l){ int max = 0; if(l == null) return 0; else { if(l.data > max){ …
2
votes
5 answers

Pythonic way to find max of columns in df within a dict

I have a dictionary which contains several, identically formatted, dataframes. I would like to find the max value of a specific column in all dataframes. I could iterate through the dictionary, but I assume there must be a more pythonic way to do…
Benjamin Brannon
  • 295
  • 1
  • 3
  • 13
2
votes
2 answers

Find MAX in Column Range ignoring Error values using Evaluate Syntax

I have defined a range called Rng. The Columns(2) of Rng contains numbers and #N/A error values. I want to find the MAX value in this column and then compare if it is >0. Col A Col B -------------- ansdlsd 1 sdlsds 1 lgdfkf 2 fdlksd …
sifar
  • 1,086
  • 1
  • 17
  • 43