def switch_guess(guesses, goatdoors):
result = np.zeros(guesses.size)
switch = {(0, 1): 2, (0, 2): 1, (1, 0): 2, (1, 2): 1, (2, 0): 1, (2, 1): 0}
for i in [0, 1, 2]:
for j in [0, 1, 2]:
mask = (guesses == i) & (goatdoors == j)
if not mask.any():
continue
result = np.where(mask, np.ones_like(result) * switch[(i, j)], result)
return result
我不太明白这是怎么回事,有人能解释一下吗? 谢谢!你知道吗
hints:
Returns The new door after switching. Should be different from both guesses and goatdoors
Examples
>>> print switch_guess(np.array([0, 1, 2]), np.array([1, 2, 1])) >>> array([2, 0, 0]) """
由于switch字典的第4个条目中的错误,您可能在理解此示例时遇到一些困难。具体如下:
我在源代码中添加了一些注释,这些注释解释了我对代码的理解。它看起来确实很像蒙蒂霍尔实验,所以我猜这个函数基本上是这样的:
如果我理解正确的话,解决这个问题似乎也有点复杂。你知道吗
相关问题 更多 >
编程相关推荐