for循环中numpy数组的计算结果错误

时间:2018-11-14 17:57:22

标签: python numpy for-loop

我有以下代码,已经在声明了numpy数组的python中计算了错误的数字:

for t in range(T-1,0,-1):
    dh[:,t,:] = dh[:,t,:] + dprev_ht
    dx[:,t,:], dprev_ht, dWxt, dWht, dbt = rnn_step_backward(dh[:,t,:], cache[t])
    dWx += dWxt
    dWh += dWht
    db += dbt

但是如果我将其更改为:

for t in range(T-1,0,-1):
    cur_dh = dh[:,t,:] + dprev_ht
    dx[:,t,:], dprev_ht, dWxt, dWht, dbt = rnn_step_backward(cur_dh, cache[t])
    dWx += dWxt
    dWh += dWht
    db += dbt

然后我可以获取正确的号码。这个问题与python中计算的顺序或优先级有关还是与for循环中numpy数组的可变性有关?还是这个问题我完全错了?

0 个答案:

没有答案