<p>我可以用几种方法再现你的错误。</p>
<p>如果<code>y0</code>参数或<code>odeint</code>的<code>t</code>参数不是一维数组,则会立即发生错误。在粘贴到pastebin(在注释中引用)上的代码示例中,<code>t</code>的形状如下:</p>
<pre><code>t = np.arange(0, 520, 1);
t = t.reshape(len(t),1);
</code></pre>
<p>删除重塑<code>t</code>形状的行。<code>t</code>必须是一维数组,而不是具有形状(len(t),1)的二维数组。</p>
<p>例如。。。</p>
<pre><code>In [177]: def SIR(x, t):
.....: return x
.....:
</code></pre>
<p>这很管用。。。</p>
<pre><code>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]])
</code></pre>
<p>这将导致错误:</p>
<pre><code>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
</code></pre>
<p>检查给<code>odeint</code>(第二个参数)的初始条件是<em>1-D</em>numpy数组(不是具有形状(1,180)或(180,1)的二维数组)。</p>
<p>如果<code>SIR</code><em>返回一个形状错误的数组,则还会出现“object too deep…”错误。它必须返回一个<em>1-D</em>数组,其形状与其第一个参数相同。确保它是真正的一维,而不是具有形状(1,180)或(180,1)的二维。</p>