How to replicate array to specific length array

There are better ways to replicate the array, for example you could simply use np.resize:

Return a new array with the specified shape.

If the new array is larger than the original array, then the new array is filled with repeated copies of a. […]

>>> import numpy as np
>>> var = [22,33,44,55]
>>> n = 13
>>> np.resize(var, n)
array([22, 33, 44, 55, 22, 33, 44, 55, 22, 33, 44, 55, 22])

Leave a Comment