如何在numpy中进行卷积矩阵运算? [英] How to do convolution matrix operation in numpy?
问题描述
是否可以使用numpy进行卷积矩阵操作?
Is there a way to do convolution matrix operation using numpy?
numpy.convolve
仅在一维数组,所以这不是解决方案.
The numpy.convolve
only operates on 1D arrays, so this is not the solution.
我宁愿避免使用scipy,因为在Windows上安装它似乎更加困难.
I rather want to avoid using scipy, since it appears to be more difficult getting installed on Windows.
推荐答案
您有scipy的 ndimage ,它允许您使用
You have scipy's ndimage which allows you to perform N-dimensional convolution with convolve:
from scipy.ndimage import convolve
convolve(data, kernel)
我知道您说过要避免臭皮……但我建议您不要这样做. Scipy在很多方面都很棒.如果要在Windows上安装它,请尝试已安装scipy的 Anaconda发行版.
I know that you said that you want to avoid scipy... but I would advise against it. Scipy is great in so many ways. If you want to install it on windows, try Anaconda Distribution, which already comes with scipy installed.
Anaconda是一个多平台的python发行版,它预先安装了所有必需的库(包括许多科学计算库),并安装了pip
或conda
之类的工具来安装新库.不,他们不付钱给我做广告:/而是让您的多平台生活变得更加轻松.
Anaconda is a multiplatform python distribution that comes with all the essential libraries (including a lot of scientific computing libraries) preinstalled, and tools like pip
or conda
to install new ones. And no, they don't pay me to advertise it :/ but makes your multiplatform life much easier.
这篇关于如何在numpy中进行卷积矩阵运算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!