I'm trying to create a numpy array of intergers ascending intergers (1,2,3,...), such that the n is repeated n times. For example for maximum number 4 I would like
my_arr = [1,2,2,3,3,3,4,4,4,4]
Now this is easy using a for loop
my_arr = numpy.array([])
max = 4
for i in range(1,max + 1):
my_arr = numpy.append(my_arr,np.ones(i)*i)
but this gets horribly slow for large numbers max.
Any suggestions?
np.repeat([1, 2, 3, 4], [1, 2, 3, 4])