<jupyter_start><jupyter_text>Introduction  This is a basic tutorial on getting direct info and help of python modules from within a Jupyter notebook. Some of this tutorial is specific to Linux (particularly the commands that start with "**!**").  Getting Basic Help from the Python interpreter Let's get help on Python's built-in abs function:<jupyter_code>help(abs)<jupyter_output>Help on built-in function abs in module __builtin__:

abs(...)
    abs(number) -> number
    
    Return the absolute value of the argument.<jupyter_text>We have to import the numpy module in order to get help on any of its functions which we attempt below. But if we ask for help on all of np (numpy), it blocks it due to simply too much output for the browser to handle. Besides, we won't be able to read it all in one sitting. So see the Help menu in the notebook web page for numpy which today points to: https://docs.scipy.org/doc/numpy/reference/<jupyter_code>import numpy as np
help(np)<jupyter_output>IOPub data rate exceeded.
The notebook server will temporarily stop sending output
to the client in order to avoid crashing it.
To change this limit, set the config variable
`--NotebookApp.iopub_data_rate_limit`.<jupyter_text>but we can execute commands from the Linux shell like this:<jupyter_code>!echo this is output from the echo command from the Linux shell
!python --version
!python -c 'print("foo"); print("bar")'<jupyter_output>foo
bar<jupyter_text>We can count the number of lines of output of whatever command we want. Here it is the simple one-liner of python that is generating two lines of output:<jupyter_code>!python -c 'print("foo"); print("bar")' | wc -l<jupyter_output>2<jupyter_text>And here is why we got the **`IOPub data rate exceeded`** error above! There is a **lot** of output from the help on the `np` module, and we do not want to see it all, anyhow.<jupyter_code>!python -c 'import numpy as np; help(np)' | wc -l<jupyter_output>90529<jupyter_text>But we can explore some of it by using basic Linux shell commands:<jupyter_code>!python -c 'import numpy as np; help(np)' | head -20<jupyter_output>Help on package numpy:

NAME
    numpy

FILE
    /home/brentg/conda/Ubuntu.16.04.miniconda2/envs/env1/lib/python2.7/site-packages/numpy/__init__.py

DESCRIPTION
    NumPy
    =====
    
    Provides
      1. An array object of arbitrary homogeneous items
      2. Fast mathematical operations over arrays
      3. Linear Algebra, Fourier Transforms, Random Number Generation
    
    How to use the documentation
    ----------------------------
    Documentation is available in two forms: docstrings provided
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/brentg/conda/Ubuntu.16.04.miniconda2/envs/env1/lib/python2.7/site.py", line 446, in __call__
    return pydoc.help(*args, **kwds)
  File "/home/brentg/conda/Ubuntu.16.04.miniconda2/envs/env1/lib/python2.7/pydoc.py", line 1795, in __call__
    self.help(request)
  File "/home/brentg/conda/Ubuntu.16.04.miniconda2/envs/env1/lib/python2.7/pydoc.py", line 1842, in help
    els[...]<jupyter_text>We can ignore the big traceback from python. All it is telling us that it failed to write to the stdout, because the `head` command is closing its side of the pipe after **20** lines of output received.That is nothing to worry about, but if we cared, we could just use **`2>/dev/null`** to send all of the error (on stderr!) to the bit bucket to hide it (which normally, we should not do because it would hide errors we do need to pay attention to, but not in this peculiar case):<jupyter_code>!python -c 'import numpy as np; help(np)' 2>/dev/null | head -20<jupyter_output>Help on package numpy:

NAME
    numpy

FILE
    /home/brentg/conda/Ubuntu.16.04.miniconda2/envs/env1/lib/python2.7/site-packages/numpy/__init__.py

DESCRIPTION
    NumPy
    =====
    
    Provides
      1. An array object of arbitrary homogeneous items
      2. Fast mathematical operations over arrays
      3. Linear Algebra, Fourier Transforms, Random Number Generation
    
    How to use the documentation
    ----------------------------
    Documentation is available in two forms: docstrings provided<jupyter_text>Getting help on numpy functions If we know what function within the particular module from online resources such as https://docs.scipy.org/doc/numpy/reference/) we are interested in, we can directly get help on it within the Jupyter notebook. But we do need to import the module before asking for it, as otherwise we will see an error:<jupyter_code>import numpy as np
help(np.linspace)<jupyter_output>Help on function linspace in module numpy.core.function_base:

linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)
    Return evenly spaced numbers over a specified interval.
    
    Returns `num` evenly spaced samples, calculated over the
    interval [`start`, `stop`].
    
    The endpoint of the interval can optionally be excluded.
    
    Parameters
    ----------
    start : scalar
        The starting value of the sequence.
    stop : scalar
        The end value of the sequence, unless `endpoint` is set to False.
        In that case, the sequence consists of all but the last of ``num + 1``
        evenly spaced samples, so that `stop` is excluded.  Note that the step
        size changes when `endpoint` is False.
    num : int, optional
        Number of samples to generate. Default is 50. Must be non-negative.
    endpoint : bool, optional
        If True, `stop` is the last sample. Otherwise, it is not included.
        Default is True.
    retstep : bo[...]<jupyter_text>Getting help on scipy functions Likewise, we can get help on scipi module functions:<jupyter_code>import numpy as np
import matplotlib as mpl

from scipy import linalg, optimize

# I don't know what difference there is between np.info and just Python's built-in help:
#   np.info(optimize.fmin)

help(optimize.fmin)<jupyter_output>Help on function fmin in module scipy.optimize.optimize:

fmin(func, x0, args=(), xtol=0.0001, ftol=0.0001, maxiter=None, maxfun=None, full_output=0, disp=1, retall=0, callback=None, initial_simplex=None)
    Minimize a function using the downhill simplex algorithm.
    
    This algorithm only uses function values, not derivatives or second
    derivatives.
    
    Parameters
    ----------
    func : callable func(x,*args)
        The objective function to be minimized.
    x0 : ndarray
        Initial guess.
    args : tuple, optional
        Extra arguments passed to func, i.e. ``f(x,*args)``.
    xtol : float, optional
        Absolute error in xopt between iterations that is acceptable for
        convergence.
    ftol : number, optional
        Absolute error in func(xopt) between iterations that is acceptable for
        convergence.
    maxiter : int, optional
        Maximum number of iterations to perform.
    maxfun : number, optional
        Maximum number of function eva[...]<jupyter_text>It seems that the `np.info` function is close to the same as the builtin `help` function:<jupyter_code>help(np.info)<jupyter_output>Help on function info in module numpy.lib.utils:

info(object=None, maxwidth=76, output=<ipykernel.iostream.OutStream object>, toplevel='numpy')
    Get help information for a function, class, or module.
    
    Parameters
    ----------
    object : object or str, optional
        Input object or name to get information about. If `object` is a
        numpy object, its docstring is given. If it is a string, available
        modules are searched for matching objects.  If None, information
        about `info` itself is returned.
    maxwidth : int, optional
        Printing width.
    output : file like object, optional
        File like object that the output is written to, default is
        ``stdout``.  The object has to be opened in 'w' or 'a' mode.
    toplevel : str, optional
        Start search at this level.
    
    See Also
    --------
    source, lookfor
    
    Notes
    -----
    When used interactively with an object, ``np.info(obj)`` is equivalent
    to ``help(obj)[...]<jupyter_text>Finding numpy functions with keywords in doc strings<jupyter_code>help(np.lookfor)
np.lookfor('root')<jupyter_output>Search results for 'root'
-------------------------
numpy.roots
    Return the roots of a polynomial with coefficients given in p.
numpy.cbrt
    Return the cube-root of an array, element-wise.
numpy.poly
    Find the coefficients of a polynomial with the given sequence of roots.
numpy.sqrt
    Return the positive square-root of an array, element-wise.
numpy.ma.sqrt
    Return the positive square-root of an array, element-wise.
numpy.polynomial.Hermite.roots
    Return the roots of the series polynomial.
numpy.polynomial.Hermite._roots
    Compute the roots of a Hermite series.
numpy.polynomial.HermiteE.roots
    Return the roots of the series polynomial.
numpy.polynomial.Laguerre.roots
    Return the roots of the series polynomial.
numpy.polynomial.Legendre.roots
    Return the roots of the series polynomial.
numpy.polynomial.HermiteE._roots
    Compute the roots of a HermiteE series.
numpy.polynomial.Laguerre._roots
    Compute the roots of a Laguerre series.
numpy.polynomial.Legendr[...]
{'fraction_non_alphanumeric': 0.0881213686249193, 'fraction_numerical': 0.010114052076608565, 'mean_word_length': 3.2676767676767677, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 40, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '32136', 'license': 'MIT', 'n_tokens_mistral': 2825, 'n_tokens_neox': 2679, 'n_words': 1108, 'path': 'python/jupyter/basic_jupyter_help_tutorial.ipynb', 'repo_name': 'bgoodr/how-to', 'size': '9294'}