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
An alternative that you can use is the numpy roll
function combined with indexing:
# -*- coding: utf-8 -*-
import numpy as np
def circular_array(starting_index, ending_index):
idx = np.arange(1,7)
idx = np.roll(idx, -starting_index)[:(len(idx)-starting_index+ending_index)%len(idx)]
return idx
a = circular_array(4, 1)
print a