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)
评论列表
文章目录