當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python SciPy linalg.polar用法及代碼示例

本文簡要介紹 python 語言中 scipy.linalg.polar 的用法。

用法:

scipy.linalg.polar(a, side='right')#

計算極分解。

返回極分解的因子[1] up這樣a = up(如果是“right”) 或a = pu(如果是“left”),其中p是半正定的。根據形狀a, 的行或列u是正交的。什麽時候a是一個方陣,u是一個方陣。什麽時候a不是方形的,“canonical polar decomposition”[2]被計算。

參數

a (m, n) 數組

要分解的數組。

side {‘left’, ‘right’},可選

確定是計算右極分解還是左極分解。如果是“right”,那麽a = up.如果是“left”,那麽a = pu.默認值為“right”。

返回

u (m, n) 數組

如果 a 是正方形,則 u 是單一的。如果 m > n,那麽 a 的列是正交的,如果 m < n,那麽 u 的行是正交的。

p ndarray

p 是厄米正半定。如果 a 是非奇異的,則 p 是正定的。 p 的形狀是 (n, n) 或 (m, m),分別取決於邊是“right” 還是“left”。

參考

[1]

R. A. Horn 和 C. R. Johnson,“Matrix Analysis”,劍橋大學出版社,1985 年。

[2]

N. J. Higham,“矩陣函數:理論與計算”,SIAM,2008 年。

例子

>>> import numpy as np
>>> from scipy.linalg import polar
>>> a = np.array([[1, -1], [2, 4]])
>>> u, p = polar(a)
>>> u
array([[ 0.85749293, -0.51449576],
       [ 0.51449576,  0.85749293]])
>>> p
array([[ 1.88648444,  1.2004901 ],
       [ 1.2004901 ,  3.94446746]])

一個非正方形的例子,m < n:

>>> b = np.array([[0.5, 1, 2], [1.5, 3, 4]])
>>> u, p = polar(b)
>>> u
array([[-0.21196618, -0.42393237,  0.88054056],
       [ 0.39378971,  0.78757942,  0.4739708 ]])
>>> p
array([[ 0.48470147,  0.96940295,  1.15122648],
       [ 0.96940295,  1.9388059 ,  2.30245295],
       [ 1.15122648,  2.30245295,  3.65696431]])
>>> u.dot(p)   # Verify the decomposition.
array([[ 0.5,  1. ,  2. ],
       [ 1.5,  3. ,  4. ]])
>>> u.dot(u.T)   # The rows of u are orthonormal.
array([[  1.00000000e+00,  -2.07353665e-17],
       [ -2.07353665e-17,   1.00000000e+00]])

另一個非正方形的例子,m > n:

>>> c = b.T
>>> u, p = polar(c)
>>> u
array([[-0.21196618,  0.39378971],
       [-0.42393237,  0.78757942],
       [ 0.88054056,  0.4739708 ]])
>>> p
array([[ 1.23116567,  1.93241587],
       [ 1.93241587,  4.84930602]])
>>> u.dot(p)   # Verify the decomposition.
array([[ 0.5,  1.5],
       [ 1. ,  3. ],
       [ 2. ,  4. ]])
>>> u.T.dot(u)  # The columns of u are orthonormal.
array([[  1.00000000e+00,  -1.26363763e-16],
       [ -1.26363763e-16,   1.00000000e+00]])

相關用法


注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.linalg.polar。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。