Python,卷积
我想在每三个幻灯片后占据MAT(矩阵)的一部分。我所拥有的代码是在一张幻灯片之后取下矩阵的一部分。 我想将矩阵的前3乘3部分乘以3列,然后向右滑动3列,然后将3乘3部分拿走,依此类推,遍历所有矩阵。
n1=np.array(([1,2,3,4,5,6],[7,8,9,10,11,12],[12,13,14,15,16,17],[18,19,20,21,22,23],[24,25,26,27,28,29],[30,31,32,33,34,35]))
print(n1)
k=3
for i in range(3):
for j in range(3):
mat = n1[i:i+k, j:j+k]
print(mat)
I want to take the part of mat (matrix) after every three slides. The code I have is taking the part of matrix after one slide.
I want to take the first 3 by 3 part of the matrix and then slide 3 columns to the right and take 3 by 3 part and so on, going through all the matrix.
n1=np.array(([1,2,3,4,5,6],[7,8,9,10,11,12],[12,13,14,15,16,17],[18,19,20,21,22,23],[24,25,26,27,28,29],[30,31,32,33,34,35]))
print(n1)
k=3
for i in range(3):
for j in range(3):
mat = n1[i:i+k, j:j+k]
print(mat)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在行和col上使用切片,例如代码bellow ...
查看文档在这里
You can use slicing on both rows and cols like the code bellow...
Check out the docs here