检查两个矩阵在python中是否相似

I have huge datasets consisting of numpy arrays. Suppose A and B are two square matrices of size n. A and B are similar if there exists a nonsingular matrix of size n, S, such that A=S^{-1}*B*S.

How can I determine if two matrices are similar in sympy/numpy? If the matrices are similar, how can I find the invertible matrix S?