floating-point

How can I round a string made of numbers efficiently using Python?

How can I round a string made of numbers efficiently using Python? Question: Using Python 3… I’ve written code that rounds the values for ArcGIS symbology labels. The label is given as a string like "0.3324 – 0.6631". My reproducible code is… label = "0.3324 – 0.6631" label_list = [] label_split = label.split(" – ") …

Total answers: 2

Python float mysteriously off by anywhere between 0.1 to 0.3

Python float mysteriously off by anywhere between 0.1 to 0.3 Question: I’m writing a function to convert a weirdly formatted Degrees Minutes Seconds to Degrees Decimal. My code is: def fromDMS(coordinate): lat_dms = coordinate[0:10] lon_dms = coordinate[11:21] lat_sign = lat_dms[0] lat_deg = float(lat_dms[1:3]) lat_min = float(lat_dms[3:5]) lat_sec = float(lat_dms[5:]) lon_sign = lon_dms[0] lon_deg = float(lon_dms[1:4]) …

Total answers: 2

Floating-point errors in cube root of exact cubic input

Floating-point errors in cube root of exact cubic input Question: I found myself needing to compute the "integer cube root", meaning the cube root of an integer, rounded down to the nearest integer. In Python, we could use the NumPy floating-point cbrt() function: import numpy as np def icbrt(x): return int(np.cbrt(x)) Though this works most …

Total answers: 1

Floating point exception (core dumped) for UNet implementation

Floating point exception (core dumped) for UNet implementation Question: I am trying to do an implementation of KiuNet ( https://github.com/jeya-maria-jose/KiU-Net-pytorch ). But when I am executing the train command like so: python train.py –train_dataset "KiuNet/Train Folder/" –val_dataset "KiuNet/Validation Folder/" –direc ‘KiuNet/Results/’ –batch_size 1 –epoch 200 –save_freq 10 –modelname "kiunet" –learning_rate 0.0001 I am getting the …

Total answers: 1

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

Convert bytestring to float in python

Convert bytestring to float in python Question: I am working on a project where I read data which is written into memory by a Delphi/Pascal program using memory mapping on a Windows PC. I am now mapping the memory again using pythons mmap and the handle given by the other program and as expected get …

Total answers: 1

How to accept the integer and float values in same input variable in python?

How to accept the integer and float values in same input variable in python? Question: How to Accept the integer and float values in the same input variable in python def interest_rate(): while True: interest_rate = input("Enter the annual interest rates: ") if interest_rate.isdigit() == True: interest_rate = int(interest_rate) if interest_rate >= 0: break else: …

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