To calculate a root square in python, there are several options:
Positive float
>>> x = 9.0
>>> x**(0.5)
3.0
with pow() function:
>>> pow(x,0.5)
3.0
with math module
>>> import math
>>> math.sqrt(x)
3.0
with numpy
>>> import numpy as np
>>> np.sqrt(x)
3.0
Complex number
>>> z = 1j
>>> z
1j
with numpy
>>> import numpy as np
>>> np.sqrt(z)
(0.7071067811865476+0.7071067811865475j)
with pow():
>>> pow(z,0.5)
(0.7071067811865476+0.7071067811865475j)
Matrix
>>> import numpy as np
>>> a = np.array((16,9,4,25))
>>> np.sqrt(a)
array([4., 3., 2., 5.])
References
Links | Site |
---|---|
Racine carrée | wikipedia |
Which is faster in Python: x**.5 or math.sqrt(x)? | stackoverflow |
How do I calculate square root in Python? | stackoverflow |
Root mean square of a function in python | stackoverflow |
Complex numbers usage in python | stackoverflow |
Nombres complexes RACINES | villemin.gerard.free.fr |