Skip to content

从线性代数到张量计算 (Tensor Computations: An Algebraic Perspective)

License

Notifications You must be signed in to change notification settings

HURONG0510/tensor-book

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

从线性代数到张量分解

MIT License Python 3.7 GitHub stars

Made by Xinyu Chen • 🌐 https://xinychen.github.io

目录

  • Kronecker分解

作者申明

  • 撰写本文的初衷在于传播知识,为感兴趣的读者提供参考素材。
  • 禁止将本文放在其他网站上供人下载,唯一下载网站为https://xinychen.github.io/books/tensor_book.pdf
  • 禁止将本文用于任何形式的商业活动。

Kronecker分解

▴ 回到顶部

例. 计算Kronecker积并求Kronecker分解。

  • 计算Kronecker积
import numpy as np

A = np.array([[1, 2], [3, 4]])
B = np.array([[5, 6, 7], [8, 9, 10]])
X = np.kron(A, B)
print('X = ')
print(X)
  • 求Kronecker分解
def permute(mat, A_dim1, A_dim2, B_dim1, B_dim2):
    ans = np.zeros((A_dim1 * A_dim2, B_dim1 * B_dim2))
    for j in range(A_dim2):
        for i in range(A_dim1):
            ans[A_dim1 * j + i, :] = mat[i * B_dim1 : (i + 1) * B_dim1,
                                         j * B_dim2 : (j + 1) * B_dim2].reshape(B_dim1 * B_dim2, order = 'F')
    return ans

X_tilde = permute(X, 2, 2, 2, 3)
print('X_tilde = ')
print(X_tilde)
print()
u, s, v = np.linalg.svd(X_tilde, full_matrices = False)
A_hat = np.sqrt(s[0]) * u[:, 0].reshape(2, 2, order = 'F')
B_hat = np.sqrt(s[0]) * v[0, :].reshape(2, 3, order = 'F')
print('A_hat = ')
print(A_hat)
print()
print('B_hat = ')
print(B_hat)

About

从线性代数到张量计算 (Tensor Computations: An Algebraic Perspective)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Jupyter Notebook 100.0%