首页 > 解决方案 > 如何在 Python 中实现 col2im()?

问题描述

im2col已经在 python 中有效地实现了,代码如下:

def im2col_sliding_strided(A, BSZ, stepsize=1):
    # Parameters
    m,n = A.shape
    s0, s1 = A.strides
    nrows = m-BSZ[0]+1
    ncols = n-BSZ[1]+1
    shp = BSZ[0],BSZ[1],nrows,ncols
    strd = s0,s1,s0,s1

    out_view = np.lib.stride_tricks.as_strided(A, shape=shp, strides=strd)
    return out_view.reshape(BSZ[0]*BSZ[1],-1)[:,::stepsize]

它来自于在 Python 中实现 MATLAB 的 im2col 'sliding'

但它没有解决方案让列重新成像。有什么方法可以加快速度吗?

标签: pythonmatlabnumpy

解决方案


推荐阅读