I'd like to find the python (numpy is possible)-equivalent of the R rep
and rep_len
functions.
Question 1: Regarding the rep_len
function, say I run,
rep_len(paste('q',1:4,sep=""), length.out = 7)
then the elements of vector ['q1','q2','q3','q4']
will be recycled to fill up 7 spaces and you'll get the output
[1] "q1" "q2" "q3" "q4" "q1" "q2" "q3"
How do I do recycle elements of a list or a 1-d numpy array to fit a predetermined length? From what I've seen numpy's repeat function lets you specify a certain number of reps, but doesn't repeat values to fill a predetermined length.
Question 2: Regarding the rep
function, say I run,
rep(2000:2004, each = 3, length.out = 14)
then the output is
[1] 2000 2000 2000 2001 2001 2001 2002 2002 2002 2003 2003 2003 2004 2004
How could I make this (recycling elements of a list or numpy array to fit a predetermined length and list each element consecutively a predetermined number of times) happen using python?
I apologize if this question has been asked before; I'm totally new to stack overflow and pretty new to programming in general.