def rank(X, cond=1.0e-12):
"""
Return the rank of a matrix X based on its generalized inverse,
not the SVD.
"""
X = np.asarray(X)
if len(X.shape) == 2:
import scipy.linalg as SL
D = SL.svdvals(X)
result = np.add.reduce(np.greater(D / D.max(), cond))
return int(result.astype(np.int32))
else:
return int(not np.alltrue(np.equal(X, 0.)))
math.py 文件源码
python
阅读 28
收藏 0
点赞 0
评论 0
评论列表
文章目录