max

Find the second largest number in array

情到浓时终转凉″ 提交于 2019-12-24 20:25:00
问题 I have an array of three element like [31,23,12] and I want to find the second largest element and its related position without rearranging the array . Example : array = [21,23,34] Second_largest = 23; Position is = 1; 回答1: Make a clone of your original array using .slice(0) like : var temp_arr = arr.slice(0); Then sor it so you get the second largest value at the index temp_arr.length - 2 of your array : temp_arr.sort()[temp_arr.length - 2] Now you could use indexOf() function to get the

Find maximum of a utility function U(h1, h2)

∥☆過路亽.° 提交于 2019-12-24 19:06:10
问题 I have a matlab function that returns the utility value U(h1, h2) that depends on the number of work hours for two persons h1 and h2 . Each person can work at maximum 3500 hours. How do I write this code in the best way? For only one person I only loop the function from input value 0 to 3500 into a matrix and find the max value in the matrix. But now I have two values that can take the value 0 to 3500 and want to find the max output from the function based on these values. I would be very

maximum of a function on a specified domain in iPython

╄→尐↘猪︶ㄣ 提交于 2019-12-24 16:57:02
问题 I am trying to find the maximum of the following function for 1 < R < 20. How can I implement this into the code? The solution is supposed to be R is approx 15.5 or so. #!/usr/bin/env python # Plotting the energy for circular Hohmann transfer import scipy import matplotlib import numpy as np import pylab def f(R): return 1 / np.sqrt(R) - (np.sqrt(2) * (1 - R)) / (np.sqrt(2) * (1 + R)) - 1 x = np.arange(1, 20) pylab.plot(x, f(x), 'r') pylab.show() 回答1: You can use scipy.optimizie.fmin : >>>

Why does Max() create an order by in the explain plan?

萝らか妹 提交于 2019-12-24 16:15:08
问题 When I attempt to do something like SELECT Max(ObjectId) FROM Objects; I see that in the explain-plan that this is performed by doing a sort. Now, sorting (which I guess would require something in the complexity of O(nlogn) ) must be much costlier than just scanning each row and remembering the max value (which could be done in O(n) ). Am I missing something here? Is oracle really performing a sort or does the explain-plan just use the description "sort" for describing a simple scan of all

Given an amount of sets with numbers, find a set of numbers not including any of the given

可紊 提交于 2019-12-24 15:20:11
问题 Given an amount of sets with numbers (0-20 e.g) , we are asked to find the maximum set of numbers from 0-20 that doesn't include any of the given sets(it can include numbers from a set,but not the whole set) For example :Setting the max number 8 and given the sets {1,2} {2,3} {7} {3,4} {5,6,4}, one maximum solution is the set {1, 3, 5, 6, 8}. I was thinking of representing it as a graph and then inducting it to the Max Independent Set problem, but that seems to work only if the sets were

MySql select all rows in one table based on MAX value in another table

依然范特西╮ 提交于 2019-12-24 13:26:11
问题 I want to be able to get all the data from table 1 and table 3 below but in addition to this I also want to get the latest application stage from table 2. The latest application stage is determined by getting the max stage_date for each application. Table 1: applications id | applicant_id | col_x | col_y | col_z ----------------------------------------- 10 300 a b c 11 310 a b c 12 320 a b c 13 330 a b c 14 340 a b c Table 2: application_progress id | application_id | application_stage |

Avoid lexicographic ordering of numerical values with Python min() max()

夙愿已清 提交于 2019-12-24 11:37:55
问题 I have a script to pull random numbers from a set of values. However, it broke today because min() and max() sort values by lexicographic order (so 200 is considered greater than 10000). How can I avoid lexicographic order here? Len key is on the right track but not quite right. I couldn't find any other key(s) that would help. data_set = 1600.csv, 2405.csv, 6800.csv, 10000.csv, 21005.csv First try: highest_value = os.path.splitext(max(data_set))[0] lowest_value = os.path.splitext(min(data

Dynamic minimum value for specfic range (mysql)

对着背影说爱祢 提交于 2019-12-24 11:29:58
问题 I am looking for a solution to SELECT (or otherwise derive) the values for Column C (minimum price for last 3 days only, not for the whole column). ---------------------------------------- Date | Unit_ | Low_3_days | | price | | ---------------------------------------- 2015-01-01 | 15 | should be: 15 | 2015-01-02 | 17 | should be: 15 | 2015-01-03 | 21 | should be: 15 | 2015-01-04 | 18 | should be: 17 | 2015-01-05 | 12 | should be: 12 | 2015-01-06 | 14 | should be: 12 | 2015-01-07 | 16 |

How to get max date from one column and match with other column in Excel?

吃可爱长大的小学妹 提交于 2019-12-24 10:56:48
问题 I have excel sheet data like below CustomerNo LoginDate 101 25/05/2012 101 10/05/2012 101 20/05/2012 101 10/04/2012 102 21/05/2012 102 12/04/2012 103 20/05/2012 104 08/04/2012 I want to get last login date match with customer number and result like below. 101 25/05/2012 102 21/05/2012 103 20/05/2012 104 08/04/2012 回答1: You may use the DMAX function to do this. First, I am putting CustomerNo in A1 and 08/04/2012 in B9. Then I am naming that range "theTable". Second, I add A11 and B11 my

Extracting the max, min or std from a DF for a particular column in pandas

Deadly 提交于 2019-12-24 10:37:00
问题 I have a df with columns X1, Y1, Z3. df.describe shows the stats for each column I would like to extract the min, max and std for say column Z3. df[df.z3].idxmax() doesn't seem to work 回答1: Demo: In [7]: df = pd.DataFrame(np.random.rand(10, 3), columns=['X1','Y1','Z3']) In [8]: df Out[8]: X1 Y1 Z3 0 0.258116 0.667943 0.954830 1 0.584975 0.546284 0.045745 2 0.698974 0.409223 0.307409 3 0.073166 0.356393 0.722233 4 0.339093 0.146043 0.614686 5 0.624361 0.062805 0.574546 6 0.886631 0.217291 0