min

Python max and min

ぐ巨炮叔叔 提交于 2019-12-08 19:16:27
问题 I'm pretty new to Python, and what makes me mad about my problem is that I feel like it's really simple.I keep getting an error in line 8. I just want this program to take the numbers the user entered and print the largest and smallest, and I want it to cancel the loop if they enter negative 1. 'int' object is not iterable is the error. print "Welcome to The Number Input Program." number = int(raw_input("Please enter a number: ")) while (number != int(-1)): number = int(raw_input("Please

R: use min() within dplyr::mutate()

 ̄綄美尐妖づ 提交于 2019-12-08 14:42:17
问题 require(plyr) require(dplyr) set.seed(8) df <- data.frame( v1 = runif(10, -1,1), v2 = runif(10, -1,1)) The problem: How can I get the correct values into the min() function as part of mutate() - basically, I would like to assign v3 as v1 divided with the smallest of v1 and v2 . This doesnt work: df <- df %>% mutate(v3=ifelse(v1 !=0, v1/min(v1,v2), 0)) I guess I am missing something really simple. 回答1: From the help page on ?min : pmax and pmin take one or more vectors (or matrices) as

Why does the negation of the minimum possible integer yield itself?

亡梦爱人 提交于 2019-12-08 11:00:02
问题 So I wrote a little experiment testing underflowing & overflowing, using c and a 64 bit machine. For type int the min/max values are: int tmax = 2147483647; int tmin = -2147483648; I know understand how two's-complement works, that isn't my question. So I thought, well what happens if I make something negative tmin? That is: int tmin = -2147483648; int negativeTmin = -tmin; It ends up still being tmin. (That is, negativeTmin will be -2147483648) My question is why is that? Since positive 2

Getting the min, max, and ave of the five numbers inputted

眉间皱痕 提交于 2019-12-08 08:32:08
问题 I'm trying to work on a program in C that gets 5 input numbers and then store these in an array. After getting the the 5 numbers, I must be getting the min, max and the average of the MINIMUN AND MAXIMUM numbers inputted and not all of the five. So here's the code that I made. When I get the maximum number, it seems to be working fine. But when it come's to the min, it's still same as the maximum and so I'll be getting a different average. #include <stdio.h> #include <conio.h> int main() {

R dplyr get name of which.min rowwise

此生再无相见时 提交于 2019-12-08 04:57:26
问题 I just answered this question with a data.table approach, and was working hard to provide a dplyr equivalent, but failed misserably. There's a simple data frame with numerical values in its columns. I want to get the name of the column with the minimum value using dplyr . Please notice that I'm aware of other methods to solve this problem: at the moment my only interest is in the dplyr approach id <- c(1,2,3,4,5,6,7,8,9,10) x1 <- c(2,4,5,3,6,4,3,6,7,7) x2 <- c(0,1,2,6,7,6,0,8,2,2) x3 <- c(5,3

SQL - Max and Min time between two fields changing

大憨熊 提交于 2019-12-08 04:54:48
问题 I have a PL/SQL table with two columns: log_date (DATE) and value (FLOAT). The data is very fine-grained, the difference between log_dates could be a few milliseconds. The value changes over time. I want to find, using SQL, the maximum and minimum amount of time between log_date s it takes for value to increase. Edit: Example log_date | value ------------------- 15:00 | 10 15:01 | 10 15:02 | 11 15:03 | 11 15:04 | 11 15:05 | 11 15:06 | 12 Between 15:00 and 15:02 value increased BUT it also

Find min value in array [closed]

一笑奈何 提交于 2019-12-08 03:22:20
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I have two arrays: int playerSums[9] = { }; string playerNames[9] = { }; I am trying to get the smallest value in the array playerSums and also the array index of this value. Here's what I've tried so far: if (playerNames[index] == "End" || playerNames[index] == "end") { int lowestValue = playerSums[0]; for (i =

How to find min/max values from rows and columns in Python?

风格不统一 提交于 2019-12-08 03:12:30
问题 I was wondering how can I find minimum and maximum values from a dataset, which is basically a text file. It has 50 rows, 50 columns. I know I can set up a control loop (for loop to be specific) to have it read each row and column, and determine the min/max values. But, I'm not sure how to do that. I think the rows and columns need to be converted to list first and then I need to use the split() function. I tried setting something up as follows, but it doesn't seem to work: for x in range(4

min() operation on nested groupby in pandas

我是研究僧i 提交于 2019-12-08 00:38:49
问题 I am just getting to know pandas and I can't get over a conceptual problem. My dataframe is as follows: df=pd.DataFrame({'ANIMAL':[1,1,1,1,1,2,2,2], 'AGE_D' : [3,6,47,377,698,1,9,241], 'AGE_Y' : [1,1,1,2,2,1,1,1]}) I would like to do a nested group within animal and age_y and then select the min on the subgroup. Desired output would be then: ANIMAL AGE_Y AGE_D 1 1 3 1 2 377 2 1 1 I can do this without nesting within animal, e.g. if my df2 = subset for ANIMAL=1 then df2.loc[df2.groupby('AGE_Y'

SQL Data Range Min Max category

半城伤御伤魂 提交于 2019-12-07 22:25:40
问题 I want to determine the range of 2 categories. Category A and Category B. A starts from 1 to 15, B starts from 16 to 31 then A Again starts from 32 to 40. Now If run this query select min(range), max(range) from table group by category order by category it gives me Range of category A from 1 to 40 and Category B from 16 to 31. I want to break the Range and want to see the results Category A 1 to 15 Category B 16 to 31 Category A 32 to 40 How do I do that? Do I need a 3rd column? I know if i