我正在使用python 2.7.3和numpy 1.6.1。我试图获得legendre和hermite多项式的高斯求积点。根据{{3}},我应该可以通过输入
来访问该属性numpy.polynomial.legendre.leggauss(1)
但每当我这样做时(即使是hermite或hermite_e)我都会收到错误
AttributeError:'module'对象没有属性'leggauss'
发生了什么事?怎么会错过这么重要的属性呢?我使用的是Mac OS X 10.7.4。下面是我在python中输入的确切代码:
Python 2.7.3 (default, Jul 12 2012, 11:58:31)
[GCC 4.2.1 Compatible Apple Clang 3.1 (tags/Apple/clang-318.0.61)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.polynomial.legendre.leggauss(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'leggauss'
>>> numpy.version.version
'1.6.1'
答案 0 :(得分:3)
如果您点击文档中的source,您会看到它在1.7.0版本中添加的注释。
def leggauss(deg):
"""
Gauss-Legendre quadrature.
Computes the sample points and weights for Gauss-Legendre quadrature.
These sample points and weights will correctly integrate polynomials of
degree :math:`2*deg - 1` or less over the interval :math:`[-1, 1]` with
the weight function :math:`f(x) = 1`.
Parameters
----------
deg : int
Number of sample points and weights. It must be >= 1.
Returns
-------
x : ndarray
1-D ndarray containing the sample points.
y : ndarray
1-D ndarray containing the weights.
Notes
-----
.. versionadded::1.7.0