matutils.py 文件源码

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

项目:discretize 作者: simpeg 项目源码 文件源码
def sub2ind(shape, subs):
    """From the given shape, returns the index of the given subscript"""
    if len(shape) == 1:
        return subs
    if type(subs) is not np.ndarray:
        subs = np.array(subs)
    if len(subs.shape) == 1:
        subs = subs[np.newaxis, :]
    assert subs.shape[1] == len(shape), (
        'Indexing must be done as a column vectors. e.g. [[3,6],[6,2],...]'
    )
    inds = np.ravel_multi_index(subs.T, shape, order='F')
    return mkvc(inds)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号