mparray.py 文件源码

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

项目:mpnum 作者: dseuss 项目源码 文件源码
def norm(mpa):
    """Computes the norm (Hilbert space norm for MPS, Frobenius norm for MPO)
    of the matrix product operator. In contrast to ``mparray.inner``, this can
    take advantage of the canonicalization

    WARNING This also changes the MPA inplace by normalizing.

    :param mpa: MPArray
    :returns: l2-norm of that array

    """
    mpa.canonicalize()
    current_lcanon, current_rcanon = mpa.canonical_form

    if current_rcanon == 1:
        return np.linalg.norm(mpa.lt[0])
    elif current_lcanon == len(mpa) - 1:
        return np.linalg.norm(mpa.lt[-1])
    else:
        raise ValueError("Normalization error in MPArray.norm")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号