circular numpy array indices

前端 未结 4 1401
既然无缘
既然无缘 2021-02-20 14:04

I have a 1-D numpy array a = [1,2,3,4,5,6] and a function that gets two inputs, starting_index and ending_index, and returns a[stari

4条回答
  •  [愿得一人]
    2021-02-20 14:32

    This circles forever.

    def circular_indices(lb, ub, thresh):
        indices = []
        while True:
            stop = min(ub, thresh)
            ix = np.arange(lb, stop)
            indices.append(ix)
            if stop != ub:
                diff = ub - stop
                lb = 0
                ub = diff
            else:
                break
    
        return np.concatenate(indices)
    

提交回复
热议问题