【发布时间】:2014-03-20 13:45:18
【问题描述】:
我正在尝试使用 scipy.integrate.romberg 进行集成,但我收到一条关于 IndexError 的错误消息:
ERROR: IndexError: 0-d arrays can't be indexed [scipy.integrate.quadrature]
Traceback (most recent call last):
File "ucmh.py", line 137, in <module>
main()
File "ucmh.py", line 128, in main
avg_rho_ucmh_squared(mDM, sigma_v, 10**5)
File "ucmh.py", line 119, in avg_rho_ucmh_squared
return n_ucmh(z) * integrate.romberg(integrand,0,R_h(z))
File "/usr/lib/python2.7/dist-packages/scipy/integrate/quadrature.py", line 596, in romberg
ordsum = _difftrap(vfunc, interval, n)
File "/usr/lib/python2.7/dist-packages/scipy/integrate/quadrature.py", line 477, in _difftrap
return 0.5*(function(interval[0])+function(interval[1]))
File "/usr/lib/python2.7/dist-packages/scipy/integrate/quadrature.py", line 94, in vfunc
y0 = func(x[0], *args)
IndexError: 0-d arrays can't be indexed
什么会导致这个问题?
【问题讨论】:
-
您确实需要发布您的代码示例以便我们为您提供帮助,但要在黑暗中大胆尝试:numpy 至少需要一个 1D 数组,而您传递给它的是 0D像
np.array(5)这样的数组,而不是像np.array([5])这样的一维数组。
标签: python python-2.7 numpy scipy