tools.py 文件源码

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

项目:brainpipe 作者: EtienneCmb 项目源码 文件源码
def adaptsize(x, where):
    """Adapt the dimension of an array depending of the tuple dim

    Args:
        x : the signal for swaping axis
        where : where each dimension should be put

    Example:
        >>> x = np.random.rand(2,4001,160)
        >>> adaptsize(x, (1,2,0)).shape -> (160, 2, 4001)
    """
    if not isinstance(where, np.ndarray):
        where = np.array(where)

    where_t = list(where)
    for k in range(len(x.shape)-1):
        # Find where "where" is equal to "k" :
        idx = np.where(where == k)[0]
        # Roll axis :
        x = np.rollaxis(x, idx, k)
        # Update the where variable :
        where_t.remove(k)
        where = np.array(list(np.arange(k+1)) + where_t)

    return x
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号