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

时间:2019-01-28 20:22:25

标签: python python-3.x

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

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

例如:

眼镜= [0,0,0,4,4,4,1,1,1,8,8,8]

我需要:

noes = [1,1,2,2,3,3,5,5,6,6,7,7,9,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)

1 个答案:

答案 0 :(得分:2)

您可以使用列表推导来获取原始列表中yeses中不在的所有值。

nos = np.repeat([x for x in allStims if x not in yeses], 2)
相关问题