tools.py 文件源码

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

项目:brainpipe 作者: EtienneCmb 项目源码 文件源码
def binArray(x, binList, axis=0):
    """Binarize an array

    x : array
        Array to binarize

    binList : list of tuple/list
        This list contain the index to binarize the array x

    axis : int, optional, [def: 0]
        Binarize along the axis "axis"

    -> Return the binarize x and the center of each window.
    """
    nbin = len(binList)
    x = np.swapaxes(x, 0, axis)

    xBin = np.zeros((nbin,)+x.shape[1::])
    for k, i in enumerate(binList):
        if i[1] - i[0] == 1:
            xBin[k, ...] = x[i[0], ...]
        else:
            xBin[k, ...] = np.mean(x[i[0]:i[1], ...], 0)

    return np.swapaxes(xBin, 0, axis), [(k[0]+k[1])/2 for k in binList]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号