How can I take the square root of -1 using python?

前端 未结 5 511
天涯浪人
天涯浪人 2020-12-06 17:59

When I take the square root of -1 it gives me an error:

invalid value encountered in sqrt

How do I fix that?

///         


        
5条回答
  •  北荒
    北荒 (楼主)
    2020-12-06 18:13

    I just discovered the convenience function numpy.lib.scimath.sqrt explained in the sqrt documentation. I use it as follows:

    >>> from numpy.lib.scimath import sqrt as csqrt
    >>> csqrt(-1)
    1j
    

提交回复
热议问题