簡體   English   中英

Python 增加列表中相同分布的元素數量

[英]Python increase the number of elements in a list with same distribution

我想通過遵循相同的分布來增加列表中的元素數量。

我的代碼:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM