Math.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:pyberny 作者: azag0 项目源码 文件源码
def pinv(A, log=lambda _: None):
    U, D, V = np.linalg.svd(A)
    thre = 1e3
    thre_log = 1e8
    gaps = D[:-1]/D[1:]
    try:
        n = np.flatnonzero(gaps > thre)[0]
    except IndexError:
        n = len(gaps)
    else:
        gap = gaps[n]
        if gap < thre_log:
            log('Pseudoinverse gap of only: {:.1e}'.format(gap))
    D[n+1:] = 0
    D[:n+1] = 1/D[:n+1]
    return U.dot(np.diag(D)).dot(V)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号