1

我正在使用 python 2.7.3 和 numpy 1.6.1。我正在尝试获得legendre 和hermite 多项式的高斯正交点。根据numpy 文档,我应该可以通过键入来访问该属性

numpy.polynomial.legendre.leggauss(1)

但是每当我这样做时(即使是 hermite 或 hermite_e)我都会得到一个错误

AttributeError:“模块”对象没有属性“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'
4

1 回答 1

3

如果您单击文档中的源代码,您将看到它是在 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
于 2012-08-10T01:28:24.633 回答