norm.py 文件源码

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

项目:mathpy 作者: aschleg 项目源码 文件源码
def pnorm(self, p):
        r"""
        Calculates the p-norm of a vector.

        Parameters
        ----------
        p : int
            Used in computing the p-norm. This should only be set
            when calculating the pnorm of a vector is desired.

        Returns
        -------
        pn : float
            The p-norm of the vector.

        Notes
        -----
        The p-norm, which is considered a class of vector norms is defined as:

        .. math::

            ||x||_p = \sqrt[p]{|x_1|^p + |x_2|^p + \cdots + |x_n|^p} \qquad p \geq 1

        References
        ----------
        Golub, G., & Van Loan, C. (2013). Matrix computations (3rd ed.). Baltimore (MD): Johns Hopkins U.P.

        """
        if p != np.floor(p):
            p = np.floor(p)

        if np.iscomplex(p) or p < 1:
            raise ValueError('p must be at least 1 and real')

        pn = np.sum(np.absolute(self.x) ** p) ** (1. / p)

        return pn
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号