stat_funcs.py 文件源码

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

项目:agdc_statistics 作者: GeoscienceAustralia 项目源码 文件源码
def section_by_index(array, index, axis=0):
    """
    Take the slice of `array` indexed by entries of `index`
    along the specified `axis`.
    """
    # alternative `axisindex` implementation
    # that avoids the index arithmetic
    # uses `numpy` fancy indexing instead

    # possible index values for each dimension represented
    # as `numpy` arrays all having the shape of `index`
    indices = np.ix_(*[np.arange(dim) for dim in index.shape])

    # the slice is taken along `axis`
    # except for the array `index` itself, the other indices
    # do nothing except trigger `numpy` fancy indexing
    fancy_index = indices[:axis] + (index,) + indices[axis:]

    # result has the same shape as `index`
    return array[fancy_index]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号