The most efficient way I can think of is to use the itertools module. First, create a cycle of each line (infinite iterator), and then select as many rows as needed islice(). The result should be a tuple or list, because numpy requires the length of the array to be explicit at build time .
import itertools as it
def extend_array(arr, length):
return np.array(tuple(it.islice(it.cycle(arr), length)))
Using:
>>> data = np.array([[0,1,2],[3,4,5],[6,7,8],[9,10,11]])
>>> extend_array(data, 10)
array([[ 0, 1, 2],
[ 3, 4, 5],
[ 6, 7, 8],
[ 9, 10, 11],
[ 0, 1, 2],
[ 3, 4, 5],
[ 6, 7, 8],
[ 9, 10, 11],
[ 0, 1, 2],
[ 3, 4, 5]])