sqrt

Python squaring a square rooted number gives a different result although it should be the original number

Python squaring a square rooted number gives a different result although it should be the original number Question: Im working on RSA so I’m dealing with very large numbers (308 digits). In RSA a number N is the product of 2 primes p and q. My N: 20254083928313901046078299908836135556415829454193867459405514358320313885965296062600909040071281223146837763723113350068483510086809787065437344845044248205975654791622356467691953988928774211033663314876745580293750456921795999384782277674803240671474563131823612882192899349325870727676292313218782419561 For the task I’m completing, I have …

Total answers: 2

is cmath.square working for numpy arrays?

Can cmath.sqrt be applied to a NumPy array? Question: I want to calculate the square root of a numpy array of negative numbers. I tried with np.sqrt() but it gives error beacuse the domain. Then, I found that for complex numbers you can use cmath.sqrt(x) but it also gives me an error. Here’s my code …

Total answers: 2

How do I calculate square root in Python?

How do I calculate square root in Python? Question: I need to calculate the square root of some numbers, for example √9 = 3 and √2 = 1.4142. How can I do it in Python? The inputs will probably be all positive integers, and relatively small (say less than a billion), but just in case …

Total answers: 10

How should I model log or sqrt with GEKKO? Constraints

How should I model log or sqrt with GEKKO? Constraints Question: I’m trying to develop my constraints with GEKKO, and I need to include some mathematical operations as log, coth or sqrt. I tried initially with my habitual procedures, using numpy or mpmath, but I figure out that using GEKKO I need to use their …

Total answers: 2

Difference between **(1/2), math.sqrt and cmath.sqrt?

Difference between **(1/2), math.sqrt and cmath.sqrt? Question: What is the difference between x**(1/2) , math.sqrt() and cmath.sqrt()? Why does cmath.sqrt() get complex roots of a quadratic right alone? Should I use that for my square roots exclusively? What do they do in the background differently? Asked By: RhythmInk || Source Answers: If you look at …

Total answers: 4

Why does math.sqrt result in ValueError: math domain error?

Why does math.sqrt result in ValueError: math domain error? Question: What causes the problem? from math import sqrt print "a : " a = float(raw_input()) print "b : " b = float(raw_input()) print "c : " c = float(raw_input()) d = (a + b + c)/2 s = sqrt(d*(d-a)*(d-b)*(d-c)) print("a+b+c =", a, b, c) print("Distr. …

Total answers: 4

Integer square root in python

Integer square root in python Question: Is there an integer square root somewhere in python, or in standard libraries? I want it to be exact (i.e. return an integer), and bark if there’s no solution. At the moment I rolled my own naive one: def isqrt(n): i = int(math.sqrt(n) + 0.5) if i**2 == n: …

Total answers: 15

Where can I inspect Python's math functions?

Where can I inspect Python's math functions? Question: I would like to look at the way Python does computes square roots, so I tried to find the definition for math.sqrt(), but I can’t find it anywhere. I have looked in _math.c, mathmodule.c, and elsewhere. I know that python uses C’s math functions, but are these …

Total answers: 4