Python创建分块循环矩阵(block circulant matrix)

2023-12-14 16:29:42
def block_circulant(A):
    """Construct a block circulant matrix from a tuple of arrays.

    Construct a block circulant matrix from a tuple of arrays. This is a
    block-matrix variant of :func:`scipy.linalg.circulant`.

    Parameters
    ----------
    A : tuple of array_like
      Tuple of arrays corresponding to the first block column of the output
      block matrix

    Returns
    -------
    B : ndarray
      Output array
    """

    r, c = A[0].shape
    B = np.zeros((len(A) * r, len(A) * c), dtype=A[0].dtype)
    for k in range(len(A)):
        for l in range(len(A)):
            kl = np.mod(k + l, len(A))
            B[r*kl:r*(kl + 1), c*k:c*(k + 1)] = A[l]
    return B


B=toeplitz(np.array(np.arange(1,4)))
C=toeplitz(np.array(np.arange(4,7)))
D=toeplitz(np.array(np.arange(7,10)))
print(block_circulant((D,C,B)))

[[7 8 9 1 2 3 4 5 6]
 [8 7 8 2 1 2 5 4 5]
 [9 8 7 3 2 1 6 5 4]
 [4 5 6 7 8 9 1 2 3]
 [5 4 5 8 7 8 2 1 2]
 [6 5 4 9 8 7 3 2 1]
 [1 2 3 4 5 6 7 8 9]
 [2 1 2 5 4 5 8 7 8]
 [3 2 1 6 5 4 9 8 7]]

https://sporco.readthedocs.io/en/latest/_modules/sporco/linalg.html#block_circulant

https://people.sc.fsu.edu/~jburkardt/m_src/toeplitz_cholesky/toeplitz_cholesky.html

文章来源:https://blog.csdn.net/y15520833229/article/details/134864642
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。