试图检查此函数中的 x、y 参数是否在相当长一段时间内相同,但似乎不起作用

Trying to check if the x, y parameter in this function has been the same for quite some time, but doesn't seem to work

所以...我正在尝试检查下面这个函数中的 x、y 参数是否在相当长一段时间内保持不变,如果是,则奖励变量应该下降...我不知道不知道我的问题是否是由于 mouseX、mouseY 值是 numpy 数组引起的,但是...

代码:

def xystoreandcheck(x, y, reward):
    global mouseX
    np.append(x, mouseX)
    global mouseY
    np.append(y, mouseY)
    if len(mouseX) > 4:
        if mouseX[-1] == mouseX[-2] or mouseX[-3] == mouseX[-1]:
            reward += -10.00
            print("Actor reward is now " + str(reward) + " due to agent failing to move mouse pointer in X coords.")
    if len(mouseY) > 4:
        if mouseY[-1] == mouseY[-2] or mouseY[-3] == mouseY[-1]:
            reward += -10.00
            print("Actor reward is now " + str(reward) + " due to agent failing to move mouse pointer in Y coords.")
    return reward

我发现有两件事可能会导致您遇到问题:

  1. np.append() 不是就地操作,因此您应该分配其 return 值。此外,第一个参数应该是数组,第二个参数是您要附加的值:mouseX = np.append(mouseX, x)

  2. 是否要检查最后三个值是否相同?那么条件中的or应该是一个and.