I want to increase the number of elements in a list by following same distribution.
My code:
# Presently I have 5 elements
x_now = [4,4.5,4.6,5.4,6]
# I want to produce 13 elements. My expected output
x_exp = [4,4.5,4.6,5.4,6,4,4.5,4.6,5.4,6,4,4.5] % I got it by copy and pasting existing list elements
# Is it possible to randomly sample between min and max here and produce n elements here:
x_exp1 =[4 4.2 4.6 4.9 5.5 5.9 4.3 4.7 4.8 5.6 6 4.1 4.6]
Option 1
(x * 2)+(x[:13%len(x)])
Option 2
[x[i%len(x)] for i in range(13)]
Something like this:
In [1431]: l = x_now * 3
In [1432]: l[:len(l)-(13 // len(x_now))]
Out[1432]: [4, 4.5, 4.6, 5.4, 6, 4, 4.5, 4.6, 5.4, 6, 4, 4.5, 4.6]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.