我有以下三个 nD 数组。
x = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
y = [[10, 11, 12],
[13, 14, 15],
[16, 17, 18]]
z = [[ 19, 20, 21],
[ 22, 23, 24],
[ 25, 26, 27]]
我想要不使用for循环,将每个2x2矩阵的元素拼接在一起:
a1 = [[1,2]
[4,5]]
a2 = [[10,11],
[13,14]]
a3 = [[19,20],
[22,23]]
should append to
a = [[1,10,19],[2,11,20],[4,13,22],[5,14,23]]
Please note, the NxN matrix will always be N = j - 1 where j is x.shape(i,j)
Similarly for other 2x2 matrices, the arrays are as follows
b = [[2,11,20],[3,12,21],[5,14,23],[6,15,24]]
c = [[4,13,22],[5,14,23],[7,16,25],[8,17,26]]
d = [[5,14,23],[6,15,24],[8,17,26],[9,18,27]]
针对大数据集,for循环会影响运行时间,因此我正在尝试使用NumPy堆叠技术来解决问题。
np.dstack
应该是您的起点。看起来您正在滑动。因此,也许可以在那里使用sckit-image的view_as_windows
。 - DivakarNxN
是什么意思?它总是会是 2x2 吗?还是对于较小的矩阵,它将是NxN
? - r4bb1t