def sympy_to_scipy_sparse(m, **options):
    if not np or not sparse:
        raise ImportError
    dtype = options.get('dtype', 'complex')
    if isinstance(m, Matrix):
        return sparse.csr_matrix(np.matrix(m.tolist(), dtype=dtype))
    elif isinstance(m, Expr):
        if m.is_Number or m.is_NumberSymbol or m == I:
            return complex(m)
    raise TypeError('Expected Matrix or complex scalar, got: %r' % m)
Convert a sympy Matrix/complex number to a numpy matrix or scalar.
dataset/ETHPy150Open sympy/sympy/sympy/physics/quantum/matrixutils.py/sympy_to_scipy_sparse