Skip to content Skip to sidebar Skip to footer

Indexerror: Index 3 Is Out Of Bounds For Axis 1 With Size 3

I would like to solve the error: IndexError: index 3 is out of bounds for axis 1 with size 3 from numpy import * from pylab import * def SIR2(I0, beta, gama, w, sigma, p, dt, t

Solution 1:

Indices of arrays in numpy start from 0. So an array with a second axis of 3, will be subscriptable up to a maximum index of 2.

So the following will not work for T[:,3]:

T=zeros([N+1,3])

If you intend to index on 0,1,2 and 3, then you should consider increasing the size of your array, say:

T=zeros([N+1,4])
#            ^ subscriptable up to 3

Post a Comment for "Indexerror: Index 3 Is Out Of Bounds For Axis 1 With Size 3"