def index_to_coords(index, shape):
    '''convert index to coordinates given the shape'''
    coords = []
    for i in xrange(1, len(shape)):
        divisor = int(np.product(shape[i:]))
        value = index // divisor
        coords.append(value)
        index -= value * divisor
    coords.append(index)
    return tuple(coords)
def index_to_coords ( index , shape ) : coords = [ ] for i in xrange ( 1 , len ( shape ) ) : divisor = int ( np . product ( shape [ i : ] ) ) value = index // divisor coords . append ( value ) index -= value * divisor coords . append ( index ) return tuple ( coords )
convert index to coordinates given the shape