embed.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:cebl 作者: idfah 项目源码 文件源码
def slidingWindow(s, span, stride=None, axis=0):
    """Sliding window.
    """
    #s = np.ascontiguousarray(s)
    s = np.require(s, requirements=['C', 'O'])

    if stride is None:
        stride = span

    # catch some bad values since this is a common place for
    # bugs to crop up in other routines
    if span > s.shape[axis]:
        raise ValueError('Span of %d exceeds input length of %d.' % (span, s.shape[axis]))

    if span < 0:
        raise ValueError('Negative span of %d is invalid.' % span)

    if stride < 1:
        raise ValueError('Stride of %d is not positive.' % stride)

    nWin = int(np.ceil((s.shape[axis]-span+1) / float(stride)))

    shape = list(s.shape)
    shape[axis] = span
    shape.insert(axis, nWin)

    strides = list(s.strides)
    strides.insert(axis, stride*strides[axis])

    return npst.as_strided(s, shape=shape, strides=strides)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号