【问题标题】:ERROR: IndexError: 0-d arrays can't be indexed [scipy.integrate.quadrature]错误:IndexError:0-d 数组无法被索引 [scipy.integrate.quadrature]
【发布时间】: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


【解决方案1】:

我的错误是集成的输入之一是 astropy.units 对象,所以它显然是一个数组,我应该传递值而不是 astropy.units 对象

【讨论】:

    猜你喜欢
    • 2018-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-16
    • 2020-10-03
    • 1970-01-01
    • 1970-01-01
    • 2021-11-03
    相关资源
    最近更新 更多