1

I need to understand the error i have view all the shapes of R and df1 respectively (2265, 2),(4616, 6) as described in the error traceback the error comes from the test pert in the loop for which is not understood. i restarted calculating the values of actions according to R from 2265

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-2-62513555e96b> in <module>()
    140     print(R.shape)
    141 
--> 142 main()
    143 
    144 

<ipython-input-2-62513555e96b> in main()
    131     #test
    132     for i in range (2265,4615,1):
--> 133         if(R[i-1,0]>R[i-1,1]):
    134             action[i]=1
    135         else:

IndexError: too many indices for array

all works well in the first part below:

#test
    for i in range (2265,4615,1):
        if(R[i-1,0]>R[i-1,1]):
            action[i]=1
        else:
            action[i]=0
        N = number_update(action,2265,4615)
        RHO = Rhoo(action,2265,4615)
        R = reward_max(action,2265,4615)
    print(R.shape)

main()
Rawia Sammout
  • 121
  • 1
  • 16
  • I see you have a `print(R)` statement right before the problem section. Could you share what `R` looks like before you go into that for loop? – divibisan May 15 '18 at 16:00
  • R is (2265, 2) [[ 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00] [ 1.09126984e-02 0.00000000e+00] [ 1.09126984e-02 2.39308262e-02] [ 1.09126984e-02 2.39308262e-02] [ 1.09126984e-02 2.39308262e-02] [ 1.09126984e-02 2.39308262e-02] – Rawia Sammout May 15 '18 at 19:48
  • You're sure that `R` is still a 2 dimensional numpy array at that point? It seems like the most common cause of this error is people working with an array that has more or less dimensions than they think it does. https://stackoverflow.com/questions/46374587/python-error-too-many-indices-for-array, https://stackoverflow.com/questions/28036812/indexerror-too-many-indices-for-array, https://stackoverflow.com/questions/29199585/indexerror-too-many-indices-numpy-array-with-1-row-and-2-columns – divibisan May 15 '18 at 19:59
  • yes R has (2265, 2) and the links didn't help to resolve my issue – Rawia Sammout May 15 '18 at 20:15

0 Answers0