I can reproduce your error in several ways.
The error occurs immediately if either the y0
argument or the t
argument to odeint
is not a 1-D array. In the code example posted on pastebin (referred to in a comment), t
is reshaped like this:
t = np.arange(0, 520, 1);
t = t.reshape(len(t),1);
Delete the line that reshapes t
. t
must be a 1-D array, not a 2-D array with shape (len(t), 1).
For example...
In [177]: def SIR(x, t):
.....: return x
.....:
This works...
In [178]: x0 = [0.1, 0.2]
In [179]: odeint(SIR, x0, t=[0, 0.5, 1])
Out[179]:
array([[ 0.1 , 0.2 ],
[ 0.16487213, 0.32974426],
[ 0.27182822, 0.54365643]])
This results in the error:
In [180]: x0 = [[0.1, 0.2]] # wrong shape
In [181]: odeint(SIR, x0, t=[0, 0.5, 1])
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-181-a37878f92395> in <module>()
----> 1 odeint(SIR, x0, t=[0, 0.5, 1])
/home/warren/anaconda/lib/python2.7/site-packages/scipy/integrate/odepack.pyc in odeint(func, y0, t, args, Dfun, col_deriv, full_output, ml, mu, rtol, atol, tcrit, h0, hmax, hmin, ixpr, mxstep, mxhnil, mxordn, mxords, printmessg)
142 output = _odepack.odeint(func, y0, t, args, Dfun, col_deriv, ml, mu,
143 full_output, rtol, atol, tcrit, h0, hmax, hmin,
--> 144 ixpr, mxstep, mxhnil, mxordn, mxords)
145 if output[-1] < 0:
146 print _msgs[output[-1]]
ValueError: object too deep for desired array
Check that the initial condition that you give to odeint
(the second argument) is a 1-D numpy array (not a 2-D array with shape (1, 180) or (180, 1)).
I also get the 'object too deep...' error if SIR
returns an array with the wrong shape. It must return a 1-D array, with the same shape as its first argument. Make sure it is truly 1-D, and not 2-D with shape (1, 180) or (180, 1).