t = "d"
A = mat(A)
eA = eye(*A.shape,**{"dtype":t})
trm = mat(eA, copy=True)
castfunc = cast[t]
for k in range(1,q):
trm *= A / castfunc(k)
eA += trm
After Change
trm = np.identity(n, dtype=t)
castfunc = cast[t]
for k in range(1, q):
trm[:] = trm.dot(A) / castfunc(k)
eA += trm
return eA