如何使用python取-1的平方根? [英] How can I take the square root of -1 using python?
本文介绍了如何使用python取-1的平方根?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我取-1的平方根时,会给我一个错误:
When I take the square root of -1 it gives me an error:
在sqrt中遇到无效的值
invalid value encountered in sqrt
我该如何解决?
/////////
arr=sqrt(-1)
print(arr)
OUTPUT
推荐答案
您需要使用 cmath 模块(标准库的一部分)
You need to use the sqrt from the cmath module (part of the standard library)
>>> import cmath
>>> cmath.sqrt(-1)
1j
这篇关于如何使用python取-1的平方根?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文