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

前端 未结 5 507
天涯浪人
天涯浪人 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条回答
  •  猫巷女王i
    2020-12-06 18:10

    Others have probably suggested more desirable methods, but just to add to the conversation, you could always multiply any number less than 0 (the value you want the sqrt of, -1 in this case) by -1, then take the sqrt of that. Just know then that your result is imaginary.

提交回复
热议问题