📜  获取给定 NumPy 数组的 QR 分解

📅  最后修改于: 2022-05-13 01:54:44.669000             🧑  作者: Mango

获取给定 NumPy 数组的 QR 分解

在本文中,我们将讨论矩阵的QR 分解QR 因式分解。矩阵的 QR 因式分解是将矩阵“A”分解为“A=QR”,其中 Q 是正交矩阵,R 是上三角矩阵。我们使用numpy.linalg.qr()函数分解矩阵。

以下是如何使用上述函数的一些示例:

示例 1: 2X2 矩阵的 QR 分解

Python3
# Import numpy package
import numpy as np
  
# Create a numpy array 
arr = np.array([[10,22],[13,6]])
  
# Find the QR factor of array
q, r =  np.linalg.qr(arr)
  
# Print the result
print("Decomposition of matrix:")
print( "q=\n", q, "\nr=\n", r)


Python3
# Import numpy package
import numpy as np
  
# Create a numpy array 
arr = np.array([[0, 1], [1, 0], [1, 1], [2, 2]])
  
# Find the QR factor of array
q, r =  np.linalg.qr(arr)
  
# Print the result
print("Decomposition of matrix:")
print( "q=\n", q, "\nr=\n", r)


Python3
# Import numpy package
import numpy as np
  
# Create a numpy array 
arr = np.array([[5, 11, -15], [12, 34, -51],
                [-24, -43, 92]], dtype=np.int32)
  
# Find the QR factor of array
q, r = np.linalg.qr(arr)
  
# Print the result
print("Decomposition of matrix:")
print( "q=\n", q, "\nr=\n", r)


输出 :

示例 2: 2X4 矩阵的 QR 分解

Python3

# Import numpy package
import numpy as np
  
# Create a numpy array 
arr = np.array([[0, 1], [1, 0], [1, 1], [2, 2]])
  
# Find the QR factor of array
q, r =  np.linalg.qr(arr)
  
# Print the result
print("Decomposition of matrix:")
print( "q=\n", q, "\nr=\n", r)

输出 :

示例 3: 3X3 矩阵的 QR 分解

Python3

# Import numpy package
import numpy as np
  
# Create a numpy array 
arr = np.array([[5, 11, -15], [12, 34, -51],
                [-24, -43, 92]], dtype=np.int32)
  
# Find the QR factor of array
q, r = np.linalg.qr(arr)
  
# Print the result
print("Decomposition of matrix:")
print( "q=\n", q, "\nr=\n", r)

输出 :