Videos
To avoid the invalid value warning/error, the argument to numpy's sqrt function must be complex:
CopyIn [8]: import numpy as np
In [9]: np.sqrt(-1+0j)
Out[9]: 1j
As @AshwiniChaudhary pointed out in a comment, you could also use the cmath standard library:
CopyIn [10]: cmath.sqrt(-1)
Out[10]: 1j
I just discovered the convenience function numpy.emath.sqrt explained in the sqrt documentation. I use it as follows:
Copy>>> from numpy.emath import sqrt as csqrt
>>> csqrt(-1)
1j
Well, you can do it using scipy.
If you want to do it with numpy however, then I think that your best guess is to diagonalize your matrix and then to compute the square root of the inner diagonal matrix.
# Computing diagonalization
evalues, evectors = np.linalg.eig(a)
# Ensuring square root matrix exists
assert (evalues >= 0).all()
sqrt_matrix = evectors * np.sqrt(evalues) @ np.linalg.inv(evectors)
Note that you can speed up computation if your matrix is symmetric real (use np.eigh and you don't have to compute the inverse since it is the transpose of evectors).
You can use https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.sqrtm.html
But note that some square roots are not unique.