Chris@87: """ Chris@87: NumPy Chris@87: ===== Chris@87: Chris@87: Provides Chris@87: 1. An array object of arbitrary homogeneous items Chris@87: 2. Fast mathematical operations over arrays Chris@87: 3. Linear Algebra, Fourier Transforms, Random Number Generation Chris@87: Chris@87: How to use the documentation Chris@87: ---------------------------- Chris@87: Documentation is available in two forms: docstrings provided Chris@87: with the code, and a loose standing reference guide, available from Chris@87: `the NumPy homepage `_. Chris@87: Chris@87: We recommend exploring the docstrings using Chris@87: `IPython `_, an advanced Python shell with Chris@87: TAB-completion and introspection capabilities. See below for further Chris@87: instructions. Chris@87: Chris@87: The docstring examples assume that `numpy` has been imported as `np`:: Chris@87: Chris@87: >>> import numpy as np Chris@87: Chris@87: Code snippets are indicated by three greater-than signs:: Chris@87: Chris@87: >>> x = 42 Chris@87: >>> x = x + 1 Chris@87: Chris@87: Use the built-in ``help`` function to view a function's docstring:: Chris@87: Chris@87: >>> help(np.sort) Chris@87: ... # doctest: +SKIP Chris@87: Chris@87: For some objects, ``np.info(obj)`` may provide additional help. This is Chris@87: particularly true if you see the line "Help on ufunc object:" at the top Chris@87: of the help() page. Ufuncs are implemented in C, not Python, for speed. Chris@87: The native Python help() does not know how to view their help, but our Chris@87: np.info() function does. Chris@87: Chris@87: To search for documents containing a keyword, do:: Chris@87: Chris@87: >>> np.lookfor('keyword') Chris@87: ... # doctest: +SKIP Chris@87: Chris@87: General-purpose documents like a glossary and help on the basic concepts Chris@87: of numpy are available under the ``doc`` sub-module:: Chris@87: Chris@87: >>> from numpy import doc Chris@87: >>> help(doc) Chris@87: ... # doctest: +SKIP Chris@87: Chris@87: Available subpackages Chris@87: --------------------- Chris@87: doc Chris@87: Topical documentation on broadcasting, indexing, etc. Chris@87: lib Chris@87: Basic functions used by several sub-packages. Chris@87: random Chris@87: Core Random Tools Chris@87: linalg Chris@87: Core Linear Algebra Tools Chris@87: fft Chris@87: Core FFT routines Chris@87: polynomial Chris@87: Polynomial tools Chris@87: testing Chris@87: Numpy testing tools Chris@87: f2py Chris@87: Fortran to Python Interface Generator. Chris@87: distutils Chris@87: Enhancements to distutils with support for Chris@87: Fortran compilers support and more. Chris@87: Chris@87: Utilities Chris@87: --------- Chris@87: test Chris@87: Run numpy unittests Chris@87: show_config Chris@87: Show numpy build configuration Chris@87: dual Chris@87: Overwrite certain functions with high-performance Scipy tools Chris@87: matlib Chris@87: Make everything matrices. Chris@87: __version__ Chris@87: Numpy version string Chris@87: Chris@87: Viewing documentation using IPython Chris@87: ----------------------------------- Chris@87: Start IPython with the NumPy profile (``ipython -p numpy``), which will Chris@87: import `numpy` under the alias `np`. Then, use the ``cpaste`` command to Chris@87: paste examples into the shell. To see which functions are available in Chris@87: `numpy`, type ``np.`` (where ```` refers to the TAB key), or use Chris@87: ``np.*cos*?`` (where ```` refers to the ENTER key) to narrow Chris@87: down the list. To view the docstring for a function, use Chris@87: ``np.cos?`` (to view the docstring) and ``np.cos??`` (to view Chris@87: the source code). Chris@87: Chris@87: Copies vs. in-place operation Chris@87: ----------------------------- Chris@87: Most of the functions in `numpy` return a copy of the array argument Chris@87: (e.g., `np.sort`). In-place versions of these functions are often Chris@87: available as array methods, i.e. ``x = np.array([1,2,3]); x.sort()``. Chris@87: Exceptions to this rule are documented. Chris@87: Chris@87: """ Chris@87: from __future__ import division, absolute_import, print_function Chris@87: Chris@87: import sys Chris@87: Chris@87: Chris@87: class ModuleDeprecationWarning(DeprecationWarning): Chris@87: """Module deprecation warning. Chris@87: Chris@87: The nose tester turns ordinary Deprecation warnings into test failures. Chris@87: That makes it hard to deprecate whole modules, because they get Chris@87: imported by default. So this is a special Deprecation warning that the Chris@87: nose tester will let pass without making tests fail. Chris@87: Chris@87: """ Chris@87: pass Chris@87: Chris@87: Chris@87: class VisibleDeprecationWarning(UserWarning): Chris@87: """Visible deprecation warning. Chris@87: Chris@87: By default, python will not show deprecation warnings, so this class Chris@87: can be used when a very visible warning is helpful, for example because Chris@87: the usage is most likely a user bug. Chris@87: Chris@87: """ Chris@87: pass Chris@87: Chris@87: Chris@87: # oldnumeric and numarray were removed in 1.9. In case some packages import Chris@87: # but do not use them, we define them here for backward compatibility. Chris@87: oldnumeric = 'removed' Chris@87: numarray = 'removed' Chris@87: Chris@87: Chris@87: # We first need to detect if we're being called as part of the numpy setup Chris@87: # procedure itself in a reliable manner. Chris@87: try: Chris@87: __NUMPY_SETUP__ Chris@87: except NameError: Chris@87: __NUMPY_SETUP__ = False Chris@87: Chris@87: Chris@87: if __NUMPY_SETUP__: Chris@87: import sys as _sys Chris@87: _sys.stderr.write('Running from numpy source directory.\n') Chris@87: del _sys Chris@87: else: Chris@87: try: Chris@87: from numpy.__config__ import show as show_config Chris@87: except ImportError: Chris@87: msg = """Error importing numpy: you should not try to import numpy from Chris@87: its source directory; please exit the numpy source tree, and relaunch Chris@87: your python interpreter from there.""" Chris@87: raise ImportError(msg) Chris@87: from .version import git_revision as __git_revision__ Chris@87: from .version import version as __version__ Chris@87: Chris@87: from ._import_tools import PackageLoader Chris@87: Chris@87: def pkgload(*packages, **options): Chris@87: loader = PackageLoader(infunc=True) Chris@87: return loader(*packages, **options) Chris@87: Chris@87: from . import add_newdocs Chris@87: __all__ = ['add_newdocs', Chris@87: 'ModuleDeprecationWarning', Chris@87: 'VisibleDeprecationWarning'] Chris@87: Chris@87: pkgload.__doc__ = PackageLoader.__call__.__doc__ Chris@87: Chris@87: from .testing import Tester Chris@87: test = Tester().test Chris@87: bench = Tester().bench Chris@87: Chris@87: from . import core Chris@87: from .core import * Chris@87: from . import compat Chris@87: from . import lib Chris@87: from .lib import * Chris@87: from . import linalg Chris@87: from . import fft Chris@87: from . import polynomial Chris@87: from . import random Chris@87: from . import ctypeslib Chris@87: from . import ma Chris@87: from . import matrixlib as _mat Chris@87: from .matrixlib import * Chris@87: from .compat import long Chris@87: Chris@87: # Make these accessible from numpy name-space Chris@87: # but not imported in from numpy import * Chris@87: if sys.version_info[0] >= 3: Chris@87: from builtins import bool, int, float, complex, object, str Chris@87: unicode = str Chris@87: else: Chris@87: from __builtin__ import bool, int, float, complex, object, unicode, str Chris@87: Chris@87: from .core import round, abs, max, min Chris@87: Chris@87: __all__.extend(['__version__', 'pkgload', 'PackageLoader', Chris@87: 'show_config']) Chris@87: __all__.extend(core.__all__) Chris@87: __all__.extend(_mat.__all__) Chris@87: __all__.extend(lib.__all__) Chris@87: __all__.extend(['linalg', 'fft', 'random', 'ctypeslib', 'ma']) Chris@87: Chris@87: # Filter annoying Cython warnings that serve no good purpose. Chris@87: import warnings Chris@87: warnings.filterwarnings("ignore", message="numpy.dtype size changed") Chris@87: warnings.filterwarnings("ignore", message="numpy.ufunc size changed")