max

for loop terminating early when comparing to Integer.MAX_VALUE and using System.out.println

余生颓废 提交于 2020-01-29 12:04:48
问题 When I run this class the for loop seems to terminate early class Test { public static void main(String[] args) { int result = 0; int end = Integer.MAX_VALUE; int i; for (i = 1; i <= end; i += 2) { System.out.println(i); } System.out.println("End:" + i); } } Output is: 1 3 5 ... 31173 31175 End:31177 Why does it end there? Interestingly if I removed the System.out.println(i) in the for loop, the output would be End:-2147483647 . Obviously the value in i has wrapped round . The Java version I

Fixed Scala code using Partition Numbers with Stream calculate, BUT too slowly

纵然是瞬间 提交于 2020-01-24 20:43:05
问题 I want to talk about how to which proceed. 1. Incorrect usage of Scala. I should try to more improve the code. 2. The efficiency of the algorithm is poor. I should think of an efficient algorithm. Goal : Can quickly calculate the max number from more than 1,000 Partition Numbers collections. Partition Number: e.g., 5 -> (5), (1, 4), (2, 3), (1, 1, 3), (1, 2, 2), (1, 1, 1, 2), (1, 1, 1, 1, 1) I ask that "I want to convert from Python to Scala that Partition Function using Vector", and I was

HOW TO: SQL Server select distinct field based on max value in other field

故事扮演 提交于 2020-01-24 19:14:41
问题 id tmpname date_used tkt_nr ---|---------|------------------|--------| 1 | template| 04/03/2009 16:10 | 00011 | 2 | templat1| 04/03/2009 16:11 | 00011 | 5 | templat2| 04/03/2009 16:12 | 00011 | 3 | diffname| 03/03/2009 15:11 | 00022 | 4 | diffname| 03/03/2009 16:12 | 00022 | 6 | another | 03/03/2009 16:13 | NULL | 7 | somethin| 24/12/2008 11:12 | 00023 | 8 | name | 01/01/2009 12:12 | 00026 | I would like to have the result: id tmpname date_used tkt_nr ---|---------|------------------|--------

HOW TO: SQL Server select distinct field based on max value in other field

ぐ巨炮叔叔 提交于 2020-01-24 19:13:25
问题 id tmpname date_used tkt_nr ---|---------|------------------|--------| 1 | template| 04/03/2009 16:10 | 00011 | 2 | templat1| 04/03/2009 16:11 | 00011 | 5 | templat2| 04/03/2009 16:12 | 00011 | 3 | diffname| 03/03/2009 15:11 | 00022 | 4 | diffname| 03/03/2009 16:12 | 00022 | 6 | another | 03/03/2009 16:13 | NULL | 7 | somethin| 24/12/2008 11:12 | 00023 | 8 | name | 01/01/2009 12:12 | 00026 | I would like to have the result: id tmpname date_used tkt_nr ---|---------|------------------|--------

python pandas-possible to compare 3 dfs of same shape using where(max())? is this a masking issue?

拟墨画扇 提交于 2020-01-24 13:23:29
问题 I have a dict containing 3 dataframes of identical shape. I would like to create: a 4th dataframe which identifies the largest value from the original 3 at each coordinate - so dic['four'].ix[0,'A'] = MAX( dic['one'].ix[0,'A'], dic['two'].ix[0,'A'], dic['three'].ix[0,'A'] ) a 5th with the second largest value dic = {} for i in ['one','two','three']: dic[i] = pd.DataFrame(np.random.randint(0,100,size=(10,3)), columns=list('ABC')) I cannot figure out how to use .where() to compare the original

Max and Min value for each colum of one Dataframe

女生的网名这么多〃 提交于 2020-01-23 12:54:28
问题 Give this dataframe 'x': col1 col2 col3 col4 0 5 -2 1 -5 2 -1 9 3 -7 3 5 How I could get a list of pairs with the min and max of each column? The result would be: list = [ [-5 , 3], [-7 , 5], [-2 , 3], [1 , 9] ] 回答1: You could define a function and call apply passing the function name, this will create a df with min and max as the index names: In [203]: def minMax(x): return pd.Series(index=['min','max'],data=[x.min(),x.max()]) df.apply(minMax) Out[203]: col1 col2 col3 col4 min -5 -7 -2 1 max

TSQL Select Max

依然范特西╮ 提交于 2020-01-23 07:57:11
问题 Userid FirstName LastName UserUpdate 1 Dan Kramer 1/1/2005 1 Dan Kramer 1/1/2007 1 Dan Kramer 1/1/2009 2 Pamella Slattery 1/1/2005 2 Pam Slattery 1/1/2006 2 Pam Slattery 1/1/2008 3 Samamantha Cohen 1/1/2008 3 Sam Cohen 1/1/2009 I need to extract the latest updated for all these users, basically here's what I'm looking for: Userid FirstName LastName UserUpdate 1 Dan Kramer 1/1/2009 2 Pam Slattery 1/1/2008 3 Sam Cohen 1/1/2009 Now when I run the following: SELECT Userid, FirstName, LastName,

A safe max() function for empty lists

爷,独闯天下 提交于 2020-01-22 08:17:26
问题 Evaluating, max_val = max(a) will cause the error, ValueError: max() arg is an empty sequence Is there a better way of safeguarding against this error other than a try , except catch? a = [] try: max_val = max(a) except ValueError: max_val = default 回答1: In Python 3.4+, you can use default keyword argument: >>> max([], default=99) 99 In lower version, you can use or : >>> max([] or [99]) 99 NOTE: The second approach does not work for all iterables. especially for iterator that yield nothing

Maximum Row in DBMS

余生长醉 提交于 2020-01-21 10:07:28
问题 Is there any limit to maximum row of table in DBMS (specially MySQL)? I want create table for saving logfile and it's row increase so fast I want know what shoud I do to prevent any problem. 回答1: You should periodically move log rows out to a historical database for data mining and purge them from the transactional database. It's a common practice. 回答2: I don't think there is an official limit, it will depend on maximum index sizes and filesystem restrictions. From mySQL 5.0 Features: Support

Image mysteriously ignoring max-width in Firefox & IE

旧巷老猫 提交于 2020-01-20 00:06:06
问题 So I'm trying to display images as big as possible with no cropping on any screen size. This means height: 100%; width: auto in landscape and width: 100%; height: auto in portrait . I'm serving up images that are big enough to fill retina iPads so pretty much every screen size will be scaling the images down. It does this fine in every browser & orientation except Internet Explorer & Firefox in landscape mode, leaving them far too big for pretty much every screen. This is only in landscape,