To avoid the warning / invalid value error, the argument of the numpy sqrt function should be complex:
In [8]: import numpy as np In [9]: np.sqrt(-1+0j) Out[9]: 1j
As @AshwiniChaudhary noted in a comment, you can also use the standard cmath library:
In [10]: cmath.sqrt(-1) Out[10]: 1j
source share