<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Background Removal with Robust PCA
视频数据集 BMC | Background Models Challenge
https
Step1:  LU 分解
将一个矩阵分解为一个上三角和下三角矩阵的乘积
Step2:  The LU factorization is useful!
Solving Ax = b becomes LUx = b
Step3:  广播运算
When operating on two arrays, NumPy compares their shapes element-wise. It starts with the trailing dimensions, and works its way forward. Two dimensions are compatible when
they are equal, or
one of them is 1
稀疏矩阵
There are the most common sparse storage formats
<ASSISTANT_TASK:>
Python Code:
# 多行结果输出支持
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
Explanation: Background Removal with Robust PCA
视频数据集 BMC | Background Models Challenge
https://www.cs.utexas.edu/~chaoyeh/web_action_data/dataset_list.html
Background Subtraction Website
End of explanation
import numpy as np
def LU(A):
    U = np.copy(A)
    m, n = A.shape
    L = np.eye(n)
    for k in range(n-1):
        for j in range(k+1,n):
            L[j,k] = U[j,k]/U[k,k]
            U[j,k:n] -= L[j,k] * U[k,k:n]
    return L, U
A = np.array([[2,1,1,0],[4,3,3,1],[8,7,9,3],[6,7,9,8]]).astype(np.float)
L, U = LU(A)
L
U
A
L @ U
np.allclose(A, L @ U)
Explanation: LU 分解
将一个矩阵分解为一个上三角和下三角矩阵的乘积
End of explanation
v=np.array([1,2,3])
v
v.shape
v1=np.expand_dims(v, -1)
v1
v1.shape
v2 = v[np.newaxis]
v2
v2.shape
v3 = v[:, np.newaxis]
v3
v3.shape
Explanation: The LU factorization is useful!
Solving Ax = b becomes LUx = b:
1. find A = LU
2. solve Ly = b
3. solve Ux = y
End of explanation
import sklearn
Explanation: 广播运算
When operating on two arrays, NumPy compares their shapes element-wise. It starts with the trailing dimensions, and works its way forward. Two dimensions are compatible when
they are equal, or
one of them is 1
稀疏矩阵
There are the most common sparse storage formats:
coordinate-wise (scipy calls COO)
compressed sparse row (CSR)
compressed sparse column (CSC)
End of explanation
<END_TASK>