subtraction

floating point subtraction in python [duplicate]

﹥>﹥吖頭↗ 提交于 2019-12-25 01:16:00
问题 This question already has answers here : Is floating point math broken? (31 answers) Closed 3 years ago . I'm trying to subtract to floating point numbers in python. I've values a = 1460356156116843.000000, b = 2301.93138123 When I try to print a-b , it's resulting the value 1460356156114541.000000 contrary to the actual value 1460356156114541.06861877 . What are the limitations in python while doing floating point arithmetic. Is there any way in python through which I can get the actual

Pandas subtract 2 rows from same dataframe

风流意气都作罢 提交于 2019-12-24 14:40:07
问题 How do I subtract one row from another in the following dataframe (df): RECL_LCC 1 2 3 RECL_LCC 35.107655 36.015210 28.877135 RECL_PI 36.961519 43.499506 19.538975 I want to do something like: df['Difference'] = df['RECL_LCC']-df['RECL_PI'] but that gives: *** KeyError: 'RECL_LCC' 回答1: You can select rows by index value using df.loc : In [98]: df.loc['Diff'] = df.loc['RECL_LCC'] - df.loc['RECL_PI'] In [99]: df Out[99]: RECL_LCC 1 2 3 RECL_LCC 35.107655 36.015210 28.877135 RECL_PI 36.961519 43

Subtract results of two Select queries in Mysql

我只是一个虾纸丫 提交于 2019-12-24 07:52:17
问题 I have written two mysql queries, one fetches me the total users(registered) present in a particular month of the year and the other fetches the active users in that particular month of the year. I need to find the number of inactive users for that year. For this, I was thinking of subtracting the totalUsers and the activeUsers columns obtained through two separate queries. Below are the queries 1. Fetch Total Registered users set @numberOfUsers := 0; SELECT T.createdMonth, T.monthlyusers, (

Subtract from negative numbers in column to use in SQL query

与世无争的帅哥 提交于 2019-12-24 07:07:09
问题 I have a set of numbers in a two column table, but I need only negative numbers subtracted by 10 and then be able to use them in a query straight after in SQLite3. I currently have the following query: 10 * (customer_x / 10), 10 * (customer_y / 10), COUNT (*) FROM t_customer GROUP BY customer_x / 10, customer_y / 10 ORDER BY 3 DESC; Which makes the values in customer_x and customer_y into fundamental co-ordinates, but any negative values will be 10 higher then the grid square they should be.

Pandas - Python - how to subtract two different date columns

萝らか妹 提交于 2019-12-23 10:07:20
问题 Trying to have a column be filled with today's date minus the created_date column, but getting the following error : TypeError: unsupported operand type(s) for -: 'str' and 'str' import datetime now = datetime.date.today() today = '{0:%m/%d/%Y}'.format(now).format(now) today data['Aging'] = today data['Aging'] = data['Aging'].sub(data['Created_Date'], axis=0) TypeError: unsupported operand type(s) for -: 'str' and 'str' 回答1: I think need subtract datetime s, so is necessary convert date in

Match rows and subtract columns

别等时光非礼了梦想. 提交于 2019-12-23 06:10:01
问题 I have 2 datasets having the same columns and different number of rows. > dput(smalldf) structure(list(X = structure(1:5, .Label = c("A", "B", "C", "F", "G"), class = "factor"), Y = c(1L, 2L, 3L, 6L, 7L), Z = c(10L, 20L, 30L, 60L, 70L)), .Names = c("X", "Y", "Z"), class = "data.frame", row.names = c(NA, -5L)) > dput(bigdf) structure(list(X = structure(1:7, .Label = c("A", "B", "C", "D", "E", "F", "G"), class = "factor"), Y = c(10L, 20L, 30L, 40L, 50L, 60L, 70L), Z = c(100L, 200L, 300L, 400L,

How to subtract values of two lists/arrays in Java?

南楼画角 提交于 2019-12-23 04:45:41
问题 I am working on a Java project and I am having a problem. I want to have the subtract of two lists or arrays a and b in list/array c but I don't know how to do that. I want "a[i] -b[i]" should be in next list c where the value should be c[i] similarly for 5-2=3 any suggestion and help would be appreciated. Code: public static void länge() { { BufferedReader br = null; try { br = new BufferedReader(new FileReader(new File("C:\\Users/Voodoothechild/Desktop/Pidata/Anfang.txt"))); String line =

Subtraction between pointers of different type [duplicate]

主宰稳场 提交于 2019-12-22 11:11:53
问题 This question already has answers here : Pointer/Address difference [duplicate] (3 answers) Closed 3 years ago . I'm trying to find the distance in memory between two variables. Specifically I need to find the distance between a char[] array and an int. char data[5]; int a = 0; printf("%p\n%p\n", &data[5], &a); long int distance = &a - &data[5]; printf("%ld\n", distance); When I run my my program without the last two lines I get the proper memory address of the two variables, something like

Protractor - compare numbers

混江龙づ霸主 提交于 2019-12-22 06:50:01
问题 In my program I'm calculating two numbers, and I want to make sure that subtraction of them equals 1. this is the code: var firstCount=element.all(by.repeater('app in userApps')).count(); var secondCount=element.all(by.repeater('app in userApps')).count(); so far it's good- I'm getting the numbers. the problem comes next: var sub=secondCount-firstCount; expect(sub).toEqual(1); I'm getting this error: Expected NaN to equal 1. any idea? 回答1: Both firstCount and secondCount are promises that are

Binary Subtraction with 2's Complement

本秂侑毒 提交于 2019-12-21 05:32:11
问题 I need help subtracting with binary using 2's representation and using 5 bits for each number: 1) -9 -7 = ? Is there overflow? -9 = 01001 (2's complement = 10111) and -7 = 00111 (2's complement = 11001) Now we need to add because we're using 2's complement 10111 +11001 = 100000 But this answer doesn't make sense. Also, I'm assuming there's overflow because there are more than 5 bits in the answer. 2) 6 - 10, same process as before. Negative binary numbers don't make sense to me 回答1: 1) -9 - 7