Python增加具有相同分布的列表中的元素数量



我想通过遵循相同的分布来增加列表中的元素数量。

我的代码:

# 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]

选项1

(x * 2)+(x[:13%len(x)])

选项2

[x[i%len(x)] for i in range(13)]

类似这样的东西:

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]

最新更新