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
评论列表
文章目录