precision

Calculate atanh with numbers very close to 1

Calculate atanh with numbers very close to 1 Question: I need to calculate the inverse hyperbolic tangent with great precision. The equation in question is -atanh(1/ (1 + 10**-x)) where x should be on the order of 240 and return the approximate value of -276.65. I tried some libraries that python provides, like numpy, math …

Total answers: 1

Check whether two lists are identical up to numerical error

Check whether two lists are identical up to numerical error Question: I have two algorithms that theoretically should perform the same task, and I want to check if they really do. They each returns a large list containing a mixture of datatypes (numbers, lists, strings). I want to check if the two lists are identical. …

Total answers: 2

How precise are eigenvalues in Python? And can precision be improved?

How precise are eigenvalues in Python? And can precision be improved? Question: When calculating eigenvalues and eigenvectors of a matrix, the eigenmatrix times itself should result in the identity matrix (E @ E.T = I). However, this is rarely the case, as some (small) errors always occurs. So question 1: how precise are eigenvalues / …

Total answers: 1

How to get the time in ms between two calls in Python

How to get the time in ms between two calls in Python Question: How does one properly get the number of millis between two successive calls? There’s a bunch of different ways to get or profile time, and all of them seem to have problems: time.clock() is deprecated time.time() is based on the system’s clock …

Total answers: 1

How to divide numbers more accurately in python pandas

How to divide numbers more accurately in python pandas Question: I’m trying to make a calculation which takes in the number 1034.55 and divide it by 0.05 and then truncate off all the numbers. If I do 1034.55/0.05 on the Windows and Android calculator, it gives 20691. Within python however, it gives: >>> 1034.55/0.05 20690.999999999996 …

Total answers: 2

Convert scientific to decimal – dynamic float precision?

Convert scientific to decimal – dynamic float precision? Question: I have a random set of numbers in a SQL database: 1.2 0.4 5.1 0.0000000000232 1 7.54 0.000000000000006534 The decimals way below zero are displayed as scientific notation num = 0.0000000000232 print(num) > 2.23e-11 But that causes the rest of my code to bug out as …

Total answers: 1

How many times can you divide 24**36 by 2 until it becomes imprecise?

How many times can you divide 24**36 by 2 until it becomes imprecise? Question: How many times can you divide 24**36 by 2 until it becomes imprecise? I had this question on one of my quizzes in a python course, and I’m curious as to what the correct answer is. (It’s already submitted so no …

Total answers: 3

Decimal Python Library has weird behavior

Decimal Python Library has weird behavior Question: I’m trying to fix all my calculation by using Python Decimal. I’m limiting the decimal places to 3, nevertheless, I’m getting this behavior: from decimal import * getcontext().prec = 3 In [0]:Decimal(‘32.983’) – Decimal(‘0.000’) Out[1]: Decimal(‘33.0’) Does anyone know how to overcome that? I would like to get: …

Total answers: 1

Can I naively check if a/b == c/d?

Can I naively check if a/b == c/d? Question: I was doing leetcode when I had to do some arithmetic with rational numbers (both numerator and denominator integers). I needed to count slopes in a list. In python collections.Counter( [ x/y if y != 0 else "inf" for (x,y) in points ] ) did the …

Total answers: 3