托普利兹矩阵的托普利兹矩阵 [英] Toeplitz matrix of toeplitz matrix

查看:24
本文介绍了托普利兹矩阵的托普利兹矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个 toeplitz 矩阵的 toeplitz 矩阵.H1、H2 和 H3 已经是托普利兹矩阵.我的结果应该是这样的:<代码>H1 0 0H2 H1 0H3 H2 H10 H3 H20 0 H3

I want to create a toeplitz matrix of toeplitz matrix. H1, H2 and H3 are toeplitz matrices already. My result should look like that: H1 0 0 H2 H1 0 H3 H2 H1 0 H3 H2 0 0 H3

现有的 toeplitz 函数只接受向量,所以我不能将它用于矩阵.目前我使用 vstack 来创建第一列,然后是第二列等等,然后我使用 hstack 来合并所有列.这需要付出很多努力,因为我必须在某些地方专门添加 np.zeros 矩阵.我想不出更好的方法来连接 numpy 数组,因为只有几个函数可以用来解决我的问题.

The existing toeplitz-function only accepts vector, so I can't use it for matrix. Currently I'm using vstack to create the first column, then second column etc. and then I use hstackto merge all columns. This takes a lot of effort, since I have to specifically add np.zeros matrices at certain places. I can't think of a better way to concatenate numpy arrays, since there are only a few functions for that and none of them really fits my problem.

推荐答案

代替对 vstackhstack 的嵌套调用,预分配最终数组会更有效率,然后使用嵌套循环填充数组.最初可以使用更高维的数组来保持代码整洁.

Instead of nested calls to vstack and hstack, it will be more efficient to preallocate the final array, and then use a nested loop to fill in the array. You can initially use a higher dimensional array to keep the code clean.

例如这个脚本

import numpy as np

H1 = np.array([[11, 11], [11, 11]])
H2 = np.array([[22, 22], [22, 22]])
H3 = np.array([[33, 33], [33, 33]])

inputs = (H1, H2, H3)

# This assumes all the arrays in `inputs` have the same shape,
# and that the data type of all the arrays is the same as H1.dtype.
nh = len(inputs)
nrows = 2*nh - 1
m, n = H1.shape
# T is a 4D array.  For a given i and j, T[i, :, j, :] is a 2D array
# with shape (m, n).  T can be intepreted as a 2D array of 2D arrays. 
T = np.zeros((nrows, m, nh, n), dtype=H1.dtype)
for i, H in enumerate(inputs):
    for j in range(nh):
        T[i + j, :, j, :] = H

# Partially flatten the 4D array to a 2D array that has the desired
# block structure.
T.shape = (nrows*m, nh*n)

print(T)

印刷品

[[11 11  0  0  0  0]
 [11 11  0  0  0  0]
 [22 22 11 11  0  0]
 [22 22 11 11  0  0]
 [33 33 22 22 11 11]
 [33 33 22 22 11 11]
 [ 0  0 33 33 22 22]
 [ 0  0 33 33 22 22]
 [ 0  0  0  0 33 33]
 [ 0  0  0  0 33 33]]

(注意,结果不是托普利茨矩阵;它是一个块托普利茨矩阵.)

(Note that the result is not a Toeplitz matrix; it is a block Toeplitz matrix.)

这篇关于托普利兹矩阵的托普利兹矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆