如何复制不是从数组中随机采样的值?

2024-09-30 02:29:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个9个元素的数组。 我随机抽取4个元素,每个元素重复3次

但我还想重复两次(在其他数组中)未采样的数字

例如:

是=[0,0,0,4,4,4,1,1,8,8]

我需要:

否=[1,1,2,2,3,3,5,5,6,6,7,9]

我该怎么做

allStims = [0, 1, 2, 3, 4, 5, 6, 7, 8]

##Pick randomly 4 numbers and repeat each 3 times
yeses = np.repeat(random.sample(allStims, 4),3)
print(yeses)

Tags: andsample元素np数字random数组randomly

热门问题