numeric_tools.py 文件源码

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

项目:kafe 作者: dsavoiu 项目源码 文件源码
def make_symmetric_lower(mat):
    '''
    Copies the matrix entries below the main diagonal to the upper triangle
    half of the matrix. Leaves the diagonal unchanged. Returns a `NumPy` matrix
    object.

    **mat** : `numpy.matrix`
        A lower diagonal matrix.

    returns : `numpy.matrix`
        The lower triangle matrix.
    '''

    # extract lower triangle from matrix (including diagonal)
    tmp_mat = np.tril(mat)

    # if the matrix given wasn't a lower triangle matrix, raise an error
    if (mat != tmp_mat).all():
        raise Exception('Matrix to symmetrize is not a lower diagonal matrix.')

    # add its transpose to itself, zeroing the diagonal to avoid doubling
    tmp_mat += np.triu(tmp_mat.transpose(), 1)

    return np.asmatrix(tmp_mat)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号