Questions tagged [minimum]

Minimum refers to the value in a collection of values that is the least or smallest.

In mathematics, the minimum of a function is the smallest value that the function takes at a point either within a given neighborhood (local or relative minimum) or on the function domain in its entirety (absolute minimum).

Examples

Python

>> import numpy as np
>> np.min([0, 1, 2])
0

See also

1056 questions
3
votes
1 answer

Better way to find a minimum value that fits a condition?

I can't get past the feeling that I am missing something obvious. Is there a clearer or more idiomatic way to do what the following function does? closest.preceding <- function(candidates, limit) { # return the value in candidates that is…
Patrick
  • 187
  • 1
  • 2
  • 7
3
votes
1 answer

Mysql min and max values and corresponding "date" for each month

I have a table named "rates" and it has two fields "date" and "rate". I like to get MIN and MAX rate values and their dates on which they occurred for each month. But I could not manage. SELECT date, MIN(rate) AS minRate, MAX(rate) AS…
mustafa
  • 747
  • 3
  • 9
  • 24
3
votes
4 answers

A fast algorithm to minimize a pseudo Diophantine equation

We're looking for an algorithm to solve this problem in under O(N). given two real numbers a and b (without loss of generality you can assume they are both between 0 and 1) Find an integer n between -N and N that minimizes the expression: |a n - b -…
John
  • 5,735
  • 3
  • 46
  • 62
3
votes
1 answer

How do I determine the maximum and minimum value for an Oracle NUMBER column?

Is there a simple formula for determining the maximum and minimum values for an Oracle NUMBER column with (p, s)?
Josh Kodroff
  • 27,301
  • 27
  • 95
  • 148
3
votes
7 answers

Fastest way of finding two minimum int64 elements in array

I have arrays with sizes from 1000 to 10000 (1k .. 10k). Each element is int64. My task is to find two smallest elements of the arrays, the minimum element and the minimum from the remaining. I want to get fastest possible single-threaded code in…
osgx
  • 90,338
  • 53
  • 357
  • 513
3
votes
1 answer

Minimum number of increments/decrements to transform string to a good form?

We are asked to modify a string by performing specific moves on it. Given a string of lowercase English characters ('a' - 'z'), two types of moves can be performed on any index, any number of times: Decrement the character by 1. The letter 'a'…
3
votes
1 answer

How to Find the Minimum Taxicab/Manhattan Distance Between Two Parallel Rectangles?

Given the coordinates of the top left corners of both rectangles, and the coordinates of the bottom right corners of both rectangles, and that the rectangles are parallel to each other, as well as the x and y axis, how do you find the minimum…
Jonathan
  • 177
  • 2
  • 7
3
votes
2 answers

Find minimum for every row in a dataframe stemming from a unique column

I need to find the row-wise minimum in an array where each minimum must stem from a unique column. For example, a is a dataframe/matrix | X1 | X2|X3| | 4 | 5 | 6| | 1 | 2 | 3| | 7 | 8 | 9| When i use rowMin, the output is 4,1,7. However, what I…
bluejay_vk
  • 33
  • 3
3
votes
2 answers

Python - Compute Local Minimum In Array Using Prefix Sums

I'm trying to solve the Min Avg Two Slice question from Codility. I came up with the following code: def solution(S, P, Q): weights = {'A': 1, 'C': 2, 'G': 3, 'T': 4} retVal = [] for i in range(0, len(P)): if P[i] == Q[i]: …
Alk
  • 5,215
  • 8
  • 47
  • 116
3
votes
3 answers

How to replace 'Zero' by 'One' for particular row in data frame

I've this dataframe:df1 DP1 DP2 DP3 DP4 DP5 DP6 DP7 DP8 DP9 DP10 OP1 43239.0 46962.0 55858.0 9128.0 30372.0 5932.0 667.0 663.0 0.0 NaN OP2 146.0 …
3
votes
2 answers

Closest element to a value (Elementwise, numpy array)

I used to use min([a, b], key=lambda x:abs(x-x0)) to find which of a and b are the closest to x0. a = 1 b = 2 x0 = 1.49 print(min([a, b], key=lambda x:abs(x-x0))) # >>> 1 Now, a and b are numpy arrays with an arbitrary number of dimensions. I would…
Liris
  • 1,399
  • 3
  • 11
  • 29
3
votes
2 answers

How to get minimum values key from hash in Perl

I have script which is able to pick minimum value from hash values. use strict; use warnings; use Data::Dumper; use List::Util qw(min); my @array = qw/50 51 52 53 54/; my $time = 1596561300; my %hash; foreach my $element(@array){ …
vkk05
  • 3,137
  • 11
  • 25
3
votes
3 answers

How do I find the two lowest values across selected columns in each row of a pandas dataframe?

In calculating grades, I drop each student's two lowest homework scores. A sample dataframe is shown here: df=pd.DataFrame([[10, 9, 10, 5, 7], [8, 7, 9, 9, 4], [10, 10, 7, 0, 8], [5, 9, 7, 6, 3], [10, 5, 0, 8, 10], [8, 9, 10, 10,…
AJCaffarini
  • 87
  • 1
  • 7
3
votes
1 answer

Is there an algorithm to find the minimum cost path in a directed rooted tree (arborescence)?

To be more specific : I have a rooted tree which represents the different paths of a matrix from its first element to its last, with only right, down and diagonal down movements allowed. Hence, every node can have up to 3 children. The tree will…
hamanic
  • 93
  • 1
  • 8
3
votes
2 answers

Negating INT_MIN in CPP

The question I am trying to solve is: Implement pow(x, n), which calculates x raised to the power n (Leetcode problem 50) I have the following code: class Solution { public: double myPow(double x, int n) { if (n == 0) { cout << "in…
hydra123
  • 337
  • 5
  • 14