我有一个包含 9 个元素的数组。 我随机采样 4 个元素,并将每个元素重复 3 次。
但我还想重复两次(在其他数组中)未采样的数字。
例如:
是= [0,0,0,4,4,4,1,1,1,8,8,8]
我需要:
没有= [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)
最佳答案
您可以使用列表理解来获取原始列表中 yes
之外的所有值。
nos = np.repeat([x for x in allStims if x not in yeses], 2)
关于python - 如何复制不是从数组中随机采样的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54409719/