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

numpy, python

Solution

You need to use the sqrt from the cmath module (part of the standard library)

>>> import cmath
>>> cmath.sqrt(-1)
1j

Problem

When I take the square root of -1 it gives me an error: invalid value encountered in sqrt How do I fix that? ``` from numpy import sqrt arr = sqrt(-1) print(arr) ```

Original source