1.6. ヘルプの入手とドキュメントの検索

Author: Emmanuelle Gouillart

NumPyとSciPyのすべての関数を知ることよりも、ドキュメントや利用可能なヘルプを通して迅速に情報を見つけることが重要です。 ここでは、情報を得るためのいくつかの方法を紹介します:

  • Ipython では、help function で関数の docstring が開きます。 関数名の先頭だけを入力し、一致する関数を表示するにはタブ補完を使ってください。

    In [1]: help(np.van<TAB>
    
    In [2]: help(np.vander)
    Help on _ArrayFunctionDispatcher in module numpy:
    vander(x, N=None, increasing=False)
    Generate a Vandermonde matrix.
    The columns of the output matrix are powers of the input vector. The
    order of the powers is determined by the `increasing` boolean argument.
    Specifically, when `increasing` is False, the `i`-th output column is
    the input vector raised element-wise to the power of ``N - i - 1``. Such
    a matrix with a geometric progression in each row is named for Alexandre-
    Theophile Vandermonde.
    Parameters
    ----------
    x : array_like
    1-D input array.
    N : int, optional
    Number of columns in the output. If `N` is not specified, a square
    array is returned (``N = len(x)``).
    increasing : bool, optional
    Order of the powers of the columns. If True, the powers increase
    from left to right, if False (the default) they are reversed.
    Returns
    -------
    out : ndarray
    Vandermonde matrix. If `increasing` is False, the first column is
    ``x^(N-1)``, the second ``x^(N-2)`` and so forth. If `increasing` is
    True, the columns are ``x^0, x^1, ..., x^(N-1)``.
    See Also
    --------
    polynomial.polynomial.polyvander
    Examples
    --------
    >>> import numpy as np
    >>> x = np.array([1, 2, 3, 5])
    >>> N = 3
    >>> np.vander(x, N)
    array([[ 1, 1, 1],
    [ 4, 2, 1],
    [ 9, 3, 1],
    [25, 5, 1]])
    >>> np.column_stack([x**(N-1-i) for i in range(N)])
    array([[ 1, 1, 1],
    [ 4, 2, 1],
    [ 9, 3, 1],
    [25, 5, 1]])
    >>> x = np.array([1, 2, 3, 5])
    >>> np.vander(x)
    array([[ 1, 1, 1, 1],
    [ 8, 4, 2, 1],
    [ 27, 9, 3, 1],
    [125, 25, 5, 1]])
    >>> np.vander(x, increasing=True)
    array([[ 1, 1, 1, 1],
    [ 1, 2, 4, 8],
    [ 1, 3, 9, 27],
    [ 1, 5, 25, 125]])
    The determinant of a square Vandermonde matrix is the product
    of the differences between the values of the input vector:
    >>> np.linalg.det(np.vander(x))
    48.000000000000043 # may vary
    >>> (5-3)*(5-2)*(5-1)*(3-2)*(3-1)*(2-1)
    48

Ipythonでは、ヘルプとドキュメント用のウィンドウを分けて開くことはできません; しかし、ヘルプとdocstringを表示するためだけに、2番目の Ipython シェルを開くことはできます...

  • Numpyのドキュメントは https://scipy.org 、Scipyのドキュメントは https://numpy.org 。 この2つのパッケージのリファレンスドキュメントは search ボタンがとても便利です。

    様々なトピックに関するチュートリアルや、すべての docstring を含む完全なAPIは、このウェブサイトにあります。

  • NumpyとScipyのドキュメントは、wiki https://numpy.org/doc/stable/ のユーザーによって定期的に充実され、更新されています。 その結果、いくつかの docstring はwikiの方がわかりやすかったり詳しかったりするので、公式ドキュメントのウェブサイトではなく、wikiのドキュメントを直接読むことをお勧めします。 誰でもwikiにアカウントを作成し、より良いドキュメントを書くことができることに注意してください。 これはオープンソースプロジェクトに貢献し、あなたが使っているツールを改善する簡単な方法です!

  • SciPy クックブック https://scipy-cookbook.readthedocs.io は、データポイントのフィッティング、ODE の解法など、頻繁に遭遇する多くの一般的な問題についてのレシピを提供しています。

  • Matplotlibのウェブサイト https://matplotlib.org/ 、多数のプロットが掲載されたとても素晴らしい ギャラリー があり、それぞれのプロットはソースコードと結果のプロットの両方を表示しています。 これは見本で学ぶのにとても便利です。 より標準的な文書も用意されています。

  • Ipythonでは、パターンにマッチするオブジェクトを検索する魔法の関数 %psearch があります。 これは、例えば関数の正確な名前がわからない場合に便利です。

    In [3]: import numpy as np
    
  • もし上記のすべてが失敗しても (そしてGoogleが答えを持っていなくても) ...絶望しないでください! 活気あるScientific Pythonコミュニティがあります。 Scientific Pythonは様々なプラットフォームに存在します。 https://scientific-python.org/community/

    SciPyやNumPyのようなパッケージにも独自のチャンネルがあります。 それぞれのウェブサイトを見て、ユーザやメンテナとの関わり方を見つけてください。