用元素乘以3d*2d元素

2024-06-16 12:45:01 发布

您现在位置:Python中文网/ 问答频道 /正文

你好,我想在系数矩阵上加权一系列图像。你知道吗

有没有办法逃过一劫并迅速做到这一点?你知道吗

for i in range(0, shape.mbn[2])
    mbn_eq[:,:,i] = mbn[:,:,i] .* coeff_n;

mbn_eq是一系列图像m*n*i,coeff_n是系数矩阵

比如说mbn

{[1,1], [1,1];
[2,2], [2,2];}

这就是系数矩阵

{[1,2], [3,4]}

所以我想要的结果是

{[1,2], [3,4];
[2,4], [6,8]}

Tags: in图像forrange矩阵eqshape系数
1条回答
网友
1楼 · 发布于 2024-06-16 12:45:01

使用numpy数组,它们在幕后支持broadcasting。你知道吗

import numpy as np 

mbn = np.array([[1,1],[1,1],[2,2],[2,2]])
mbn = mbn.reshape(2,2,2)
print(mbn)
print(mbn.shape)
coeff = np.array([[1,2], [3,4]])

print(mbn * coeff)

相关问题 更多 >