I want replicate a small array to specific length array
Example:
var = [22,33,44,55] # ==> len(var) = 4
n = 13
The new array that I want would be:
var_new = [22,33,44,55,22,33,44,55,22,33,44,55,22]
This is my code:
import numpy as np
var = [22,33,44,55]
di = np.arange(13)
var_new = np.empty(13)
var_new[di] = var
I get error message:
DeprecationWarning: assignment will raise an error in the future, most likely because your index result shape does not match the value array shape. You can use
arr.flat[index] = values
to keep the old behaviour.
But I get my corresponding variable:
var_new
array([ 22., 33., 44., 55., 22., 33., 44., 55., 22., 33., 44.,
55., 22.])
So, how to solve the error? Is there an alternative?
See also Repeat list to max number of elements for general methods not specific to Numpy.
See also Circular list iterator in Python for lazy iteration over such data.