as a linear operator, you could use scipy's signal.convolve2d function to do exactly that. For instance, say you have an 50x50 array, A, and you want to calculate a second array B where each of its element b[ij] is the average over a[i,j], a[(i-1),j], a[i,(j-1)], a[(i-1),(j-1)] from the array A. You could do that simply doing :A = # your first arrayB = numpy.ones((2,2))/4C = scipy.signal.convolve2d(A,B, 'valid')进行卷积时,数组B在A上滑动",将相应的元素相乘并求和.由于边界效应,在使用结果数组C时必须小心.在这里,由于convolve2d中的'valid'参数,C的形状为49x49,因为它们包含边界效应,所以要丢弃第一行和第一列.如果您希望有一个50x50的数组而不丢弃,则可以将该参数替换为'same' When the convolution is performed, the array B "slides" across A, multiplying the corresponding elements and summing up the result. Because of border effects, you must be careful when using the resulting array C. Here, C is of shape 49x49, because of the 'valid' argument in convolve2d, to discard the first row and column since they contain border effects. If you wanted to have a 50x50 array, without discarding, you would swap that argument for 'same' 编辑:也许,如果您能告诉我更多有关所需功能的信息,我可以帮助您更具体地将其转换为用于进行2D卷积的数组.EDIT: Perhaps if you could tell me more about that function you need, I could help you more specifically in turning it into an array that would be used to do the 2D convolution.希望有帮助! 这篇关于在numpy中的二维数组上的矢量化移动窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-17 01:02