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

Pandas: How to find the low after a high within a rolling window

For a series of numbers, I am trying to find the low after the high within a rolling window. I am able to calculate the high within the window, but not the low after it within the same window. I'm using Pandas and have tried to get the index of…
2
votes
1 answer

How to apply Normalisation using the MinMaxScaler() to all Columns, but Exclude the Categorical?

I am new to using the MinMaxScaler, so please do not bite my head of if this is a very, very simple question. Below, I have the following datatset: sample_df.head(2) ID S_LENGTH S_WIDTH P_LENGTH P_WIDTH …
user14924411
2
votes
3 answers

Pandas Min and Max Across Rows

I have a dataframe that looks like below. I want to get a min and max value per city along with the information about which products were ordered min and max for that city. Please help. Dataframe
2
votes
2 answers

How to delete the highest value in a row

I have a dataframe with 5 values per row. I need to calculate the mean of the 4 lowest values. So, I would like to delete the highest value in each row and then calculate the mean. For me, it does not matter in which column the highest value…
NienkeH
  • 67
  • 4
2
votes
2 answers

Calculate sum of maximum and minimum value for repeated group of entries in MySQL8

LogDateAndTime BatchDate TagLetter Totaliser ExpectedResult 10-11-2020 09:06:14 10-11-2020 08:29:55 A 6319 31 10-11-2020 09:06:24 10-11-2020 08:29:55 A 6337 31 10-11-2020 09:08:14 10-11-2020 08:29:55 B 6355 31 10-11-2020…
Midhunraj
  • 23
  • 4
2
votes
4 answers

How to select max value by condition and then compare it with others?

I have a backup set that is described by json. Sample is below. I want to count how much increment backups were added since the last full backup. I try to select max timestamp of the record with type "full" so after that i will count how much…
Pavel Polushin
  • 351
  • 2
  • 5
  • 16
2
votes
1 answer

How can I get the dict whose specific key is maximum in a dict of dicts?

Say I have a dictionary with max and min temperatures of every month: t = { 'jan': { 'max': 21, 'min': 12 }, 'feb': { 'max': 18, 'min': 15 }, 'mar': { 'max': 20, 'min': 17 …
fedorqui
  • 275,237
  • 103
  • 548
  • 598
2
votes
0 answers

Confusions about the system brightness under Android

Confusions about the system brightness under Android. I use Android 10.0+ (R) with SDK 30.0.2. The system brightness and its objects are documented in: https://developer.android.com/reference/android/provider/Settings.System#SCREEN_BRIGHTNESS There…
Collin01
  • 41
  • 1
2
votes
1 answer

How do I clamp __m128i signed integers into non-negative unsigned integers in SSE

I can't figure out how to convert 4 x 32 bit signed integers stored in a single __m128i into "unsigned" counterparts. The conversion should be done with value truncation, clamping negative numbers to 0 but leaving non-negative numbers…
lhog
  • 105
  • 1
  • 8
2
votes
0 answers

Pandas get a maximum value from multiple columns and rolling time index

I am going to get a maximum value from multiple columns and a rolling time index. How can I do it? For example, I would like to get the maximum (and median) value from 3 days (+/- 1 day) and multiple columns 1006 1037 1041 …
linyenheng
  • 33
  • 3
2
votes
3 answers

Update Dataframe Column based on Grouping and Conditionals

I have three columns which represent my data. I am trying to update the final column 'Val' based on the input of the first two. I want the maximum of the 'Range', categorised by the 'Cat' column. Following that, I would like to update the 'Val'…
itsgupta
  • 123
  • 2
2
votes
2 answers

How to SELECT lines where COUNT DISTINCT is MAX?

this may be an easy question but basically I would like to get to SELECT only the lines of highest number of occurence for an experiment in SQL SERVER. I have a query that produces the following data: SELECT [JOB ROLE], [CITY],…
gonzika
  • 23
  • 3
2
votes
1 answer

haskell second largest element from list

I have this function that returns the second largest value from a given list: import Data.List secondL :: Ord a => [a] -> a secondL xs = let x = head xs in let find (a, b) x = (min b (max a x), max b x) in fst (foldl find (x, x)…
enneenne
  • 209
  • 1
  • 8
2
votes
1 answer

Maximum subarray of size HxW within a big 2D bit matrix

I have a big NxN bit array with K ones (everything else is zero). Coordinates of all non-zero points are known - in other words this NxN array can be represented as an array of K pairs each containing x and y coords of a non-zero point. Given a…
Igor
  • 163
  • 6
2
votes
4 answers

Javascript- How to write a function that finds the max number in any set of numerical arguments

I am completing an exercise on JavaScript Hero (https://www.jshero.net/en/success.html) and I was able to get the function to work, however, I'm hoping someone could tell me WHY it works. I'd really appreciate it. The challenge is... "Write a…
jane doe
  • 25
  • 5