min

Find max(and min) on the moving interval using python

人走茶凉 提交于 2019-12-05 14:18:34
I have a array like [5.5, 6.0, 6.0, 6.5, 6.0, 5.5, 5.5, 5.0, 4.5]. all numbers of this array differ by 0.5, and the maximum difference of two successive numbers is also 0.5(they can be same; as in the example). and there is a moving interval, or box, which covers, for example, 3 successive numbers, like this: [(5.5, 6.0, 6.0), 6.5, 6.0, 5.5, 5.5, 5.0, 4.5] # min: 5.5, max: 6.0 and the box moves toward right one by one: [5.5, (6.0, 6.0, 6.5), 6.0, 5.5, 5.5, 5.0, 4.5] # min: 6.0, max: 6.5 [5.5, 6.0, (6.0, 6.5, 6.0), 5.5, 5.5, 5.0, 4.5] # min: 6.0, max: 6.5 the question is, how can I find the min

Minimum Value MySQL Query

≯℡__Kan透↙ 提交于 2019-12-05 12:43:31
I have a data table similar to below: ID A B 10 5 blue 10 8 red 10 10 yellow 20 2 black 20 17 blue 30 7 red 30 12 green 30 50 black Basically I want to write a mySQL query to output something like: ID A B 10 5 blue 20 2 black 30 7 red It gives only unique values of 'ID' and the minimum values of 'A' of each unique 'ID'. 'B' is just the extra data that goes along with it in the row. What should my query look like? You can use a subquery to identify the min(a) value for each id and then join that back to your table: select * from yourtable t1 inner join ( select min(A) A, id from yourtable group

Aggregate with max and factors

邮差的信 提交于 2019-12-05 12:22:57
I have a data.frame with columns of factors, on which I want to compute a max (or min, or quantiles). I can't use these functions on factors, but I want to. Here's some example : set.seed(3) df1 <- data.frame(id = rep(1:5,each=2),height=sample(c("low","medium","high"),size = 10,replace=TRUE)) df1$height <- factor(df1$height,c("low","medium","high")) df1$height_num <- as.numeric(df1$height) # > df1 # id height height_num # 1 1 low 1 # 2 1 high 3 # 3 2 medium 2 # 4 2 low 1 # 5 3 medium 2 # 6 3 medium 2 # 7 4 low 1 # 8 4 low 1 # 9 5 medium 2 # 10 5 medium 2 I can easily do this: aggregate(height

Using MIN() inside ARRAYFORMULA()

左心房为你撑大大i 提交于 2019-12-05 06:49:13
I've seen some examples of using SUM() inside an ARRAYFORMULA() in Google Spreadsheets (and oddly enough, they all seem like workarounds) but I can't figure out how to apply them to using MIN() instead. Let's say I have columns A , B and C and I just want to get the result of MIN(A:C) on the D column, just for the three cells that would match each row. The straightforward way should be ARRAYFORMULA(MIN(A1:C)) but surely enough that doesn't work. How can I programmatically calculate the MIN() of some cells within a row, for all the rows in a Google Spreadsheet? MIN() always returns a single

MySQL MIN/MAX all row

ⅰ亾dé卋堺 提交于 2019-12-05 03:24:13
问题 I have table Races with the rows ID , Name and TotalCP . I SELECT MIN( TotalCP ) FROM Races , but then I want to select the entire row which have the minimum value. How I can make that, in a single query ? 回答1: The general form for getting a whole row from an aggregated value is: SELECT * FROM Races WHERE TotalCP = (SELECT MIN(TotalCP) FROM Races) or SELECT r.* FROM ( SELECT MIN(TotalCP) t FROM Races ) m INNER JOIN Races r ON m.t = r.TotalCP However, in this case, since you're using MIN , you

Find both min and max together: algorithm should be faster but isn't

大城市里の小女人 提交于 2019-12-04 19:31:33
I'm trying to implement an algorithm to find the minimum and the maximum values among a set of longs in a file. My test file contains one billion longs. The algorithm works as expected but does not perform faster than the naive version. It should be significantly faster as the naive version performs roughly 2n comparisons, whereas this version performs 3n/2 comparisons. $ time ./findminmax_naive somelongs count: 1000000000 min: 0 max: 2147483647 real 0m24.156s user 0m4.956s sys 0m3.896s $ time ./findminmax_faster somelongs count: 1000000000 min: 0 max: 2147483647 real 0m25.048s user 0m6.948s

min(column) is not returning me correct data of other columns

扶醉桌前 提交于 2019-12-04 16:46:51
Below is what I have +++++++++++++++++++++++++++ id + myDate + name +++++++++++++++++++++++++++ 'A'+ '2012-06-05' + 'baz' 'A'+ '2012-06-04' + 'bar' 'B'+ '2012-06-05' + 'foo' 'C'+ '2012-06-05' + 'bla' 'C'+ '2012-06-04' + 'blah' 'C'+ '2012-06-06' + 'bleh' +++++++++++++++++++++++++++ Query I am using is SELECT id, min(myDate) as Date, name FROM myTable GROUP BY id; I am getting output as below +++++++++++++++++++++++++++ id + myDate + name +++++++++++++++++++++++++++ 'A'+ '2012-06-04' + 'baz' 'B'+ '2012-06-05' + 'foo' 'C'+ '2012-06-04' + 'bla' +++++++++++++++++++++++++++ My question is when query

Manage empty list/invalid input when finding max/min value of list (Python)

女生的网名这么多〃 提交于 2019-12-04 15:09:14
问题 I'm finding max value and min value of a list by using max(list) and min(list) in Python. However, I wonder how to manage empty lists. For example if the list is an empty list [] , the program raises 'ValueError: min() arg is an empty sequence' but I would like to know how to make the program just print 'empty list or invalid input' instead of just crashing. How to manage those errors? 回答1: Catch and handle the exception. try: print(min(l), max(l)) except (ValueError, TypeError): print('empty

karger min cut algorithm in python 2.7

帅比萌擦擦* 提交于 2019-12-04 13:06:17
问题 Here is my code for the karger min cut algorithm.. To the best of my knowledge the algorithm i have implemented is right. But I don get the answer right. If someone can check what's going wrong I would be grateful. import random from random import randint #loading data from the text file# with open('data.txt') as req_file: mincut_data = [] for line in req_file: line = line.split() if line: line = [int(i) for i in line] mincut_data.append(line) #extracting edges from the data # edgelist = []

SELECT min and max value from a part of a table in MySQL

旧城冷巷雨未停 提交于 2019-12-04 11:03:32
问题 If I want to select min and max values from a whole table I can use this: SELECT min(price) as min_price, max(price) as max_price FROM `prices` But how to select min and max values from just a part of a table? For example, I have 30 rows in a table. I want to select min and max values from first ten rows, then from second ten rows and then form the last 10. I've tried something like SELECT min(price) as min_price, max(price) as max_price FROM `prices` LIMIT 0,10 but this did not work. How can