def binary_fill_holes(input, structure=None, output=None, origin=<NUM_LIT:0>):

mask = numpy.logical_not(input)<EOL>tmp = numpy.zeros(mask.shape, bool)<EOL>inplace = isinstance(output, numpy.ndarray)<EOL>if inplace:<EOL><INDENT>binary_dilation(tmp, structure, -<NUM_LIT:1>, mask, output, <NUM_LIT:1>, origin)<EOL>numpy.logical_not(output, output)<EOL><DEDENT>else:<EOL><INDENT>output = binary_dilation(tmp, structure, -<NUM_LIT:1>, mask, None, <NUM_LIT:1>,<EOL>origin)<EOL>numpy.logical_not(output, output)<EOL>return output<EOL><DEDENT>

Fill the holes in binary objects.

Parameters
----------
input : array_like
    n-dimensional binary array with holes to be filled
structure : array_like, optional
    Structuring element used in the computation; large-size elements
    make computations faster but may miss holes separated from the
    background by thin regions. The default element (with a square
    connectivity equal to one) yields the intuitive result where all
    holes in the input have been filled.
output : ndarray, optional
    Array of the same shape as input, into which the output is placed.
    By default, a new array is created.
origin : int, tuple of ints, optional
    Position of the structuring element.

Returns
-------
out : ndarray
    Transformation of the initial image `input` where holes have been
    filled.

See also
--------
binary_dilation, binary_propagation, label

Notes
-----
The algorithm used in this function consists in invading the complementary
of the shapes in `input` from the outer boundary of the image,
using binary dilations. Holes are not connected to the boundary and are
therefore not invaded. The result is the complementary subset of the
invaded region.

References
----------
.. [1] http://en.wikipedia.org/wiki/Mathematical_morphology

Examples
--------
>>> a = np.zeros((5, 5), dtype=int)
>>> a[1:4, 1:4] = 1
>>> a[2,2] = 0
>>> a
array([[0, 0, 0, 0, 0],
       [0, 1, 1, 1, 0],
       [0, 1, 0, 1, 0],
       [0, 1, 1, 1, 0],
       [0, 0, 0, 0, 0]])
>>> ndimage.binary_fill_holes(a).astype(int)
array([[0, 0, 0, 0, 0],
       [0, 1, 1, 1, 0],
       [0, 1, 1, 1, 0],
       [0, 1, 1, 1, 0],
       [0, 0, 0, 0, 0]])
>>> # Too big structuring element
>>> ndimage.binary_fill_holes(a, structure=np.ones((5,5))).astype(int)
array([[0, 0, 0, 0, 0],
       [0, 1, 1, 1, 0],
       [0, 1, 0, 1, 0],
       [0, 1, 1, 1, 0],
       [0, 0, 0, 0, 0]])


def grey_erosion(input, size=None, footprint=None, structure=None,<EOL>output=None, mode="<STR_LIT>", cval=<NUM_LIT:0.0>, origin=<NUM_LIT:0>):

if size is None and footprint is None and structure is None:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return filters._min_or_max_filter(input, size, footprint, structure,<EOL>output, mode, cval, origin, <NUM_LIT:1>)<EOL>

Calculate a greyscale erosion, using either a structuring element,
or a footprint corresponding to a flat structuring element.

Grayscale erosion is a mathematical morphology operation. For the
simple case of a full and flat structuring element, it can be viewed
as a minimum filter over a sliding window.

Parameters
----------
input : array_like
    Array over which the grayscale erosion is to be computed.
size : tuple of ints
    Shape of a flat and full structuring element used for the grayscale
    erosion. Optional if `footprint` or `structure` is provided.
footprint : array of ints, optional
    Positions of non-infinite elements of a flat structuring element
    used for the grayscale erosion. Non-zero values give the set of
    neighbors of the center over which the minimum is chosen.
structure : array of ints, optional
    Structuring element used for the grayscale erosion. `structure`
    may be a non-flat structuring element.
output : array, optional
    An array used for storing the ouput of the erosion may be provided.
mode : {'reflect','constant','nearest','mirror', 'wrap'}, optional
    The `mode` parameter determines how the array borders are
    handled, where `cval` is the value when mode is equal to
    'constant'. Default is 'reflect'
cval : scalar, optional
    Value to fill past edges of input if `mode` is 'constant'. Default
    is 0.0.
origin : scalar, optional
    The `origin` parameter controls the placement of the filter.
    Default 0

Returns
-------
output : ndarray
    Grayscale erosion of `input`.

See also
--------
binary_erosion, grey_dilation, grey_opening, grey_closing
generate_binary_structure, ndimage.minimum_filter

Notes
-----
The grayscale erosion of an image input by a structuring element s defined
over a domain E is given by:

(input+s)(x) = min {input(y) - s(x-y), for y in E}

In particular, for structuring elements defined as
s(y) = 0 for y in E, the grayscale erosion computes the minimum of the
input image inside a sliding window defined by E.

Grayscale erosion [1]_ is a *mathematical morphology* operation [2]_.

References
----------
.. [1] http://en.wikipedia.org/wiki/Erosion_%28morphology%29
.. [2] http://en.wikipedia.org/wiki/Mathematical_morphology

Examples
--------
>>> a = np.zeros((7,7), dtype=np.int)
>>> a[1:6, 1:6] = 3
>>> a[4,4] = 2; a[2,3] = 1
>>> a
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 3, 3, 3, 3, 3, 0],
       [0, 3, 3, 1, 3, 3, 0],
       [0, 3, 3, 3, 3, 3, 0],
       [0, 3, 3, 3, 2, 3, 0],
       [0, 3, 3, 3, 3, 3, 0],
       [0, 0, 0, 0, 0, 0, 0]])
>>> ndimage.grey_erosion(a, size=(3,3))
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 3, 2, 2, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]])
>>> footprint = ndimage.generate_binary_structure(2, 1)
>>> footprint
array([[False,  True, False],
       [ True,  True,  True],
       [False,  True, False]], dtype=bool)
>>> # Diagonally-connected elements are not considered neighbors
>>> ndimage.grey_erosion(a, size=(3,3), footprint=footprint)
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 3, 1, 2, 0, 0],
       [0, 0, 3, 2, 2, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]])


def grey_dilation(input, size=None, footprint=None, structure=None,<EOL>output=None, mode="<STR_LIT>", cval=<NUM_LIT:0.0>, origin=<NUM_LIT:0>):

if size is None and footprint is None and structure is None:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if structure is not None:<EOL><INDENT>structure = numpy.asarray(structure)<EOL>structure = structure[tuple([slice(None, None, -<NUM_LIT:1>)] *<EOL>structure.ndim)]<EOL><DEDENT>if footprint is not None:<EOL><INDENT>footprint = numpy.asarray(footprint)<EOL>footprint = footprint[tuple([slice(None, None, -<NUM_LIT:1>)] *<EOL>footprint.ndim)]<EOL><DEDENT>input = numpy.asarray(input)<EOL>origin = _ni_support._normalize_sequence(origin, input.ndim)<EOL>for ii in range(len(origin)):<EOL><INDENT>origin[ii] = -origin[ii]<EOL>if footprint is not None:<EOL><INDENT>sz = footprint.shape[ii]<EOL><DEDENT>elif structure is not None:<EOL><INDENT>sz = structure.shape[ii]<EOL><DEDENT>elif numpy.isscalar(size):<EOL><INDENT>sz = size<EOL><DEDENT>else:<EOL><INDENT>sz = size[ii]<EOL><DEDENT>if not sz & <NUM_LIT:1>:<EOL><INDENT>origin[ii] -= <NUM_LIT:1><EOL><DEDENT><DEDENT>return filters._min_or_max_filter(input, size, footprint, structure,<EOL>output, mode, cval, origin, <NUM_LIT:0>)<EOL>

Calculate a greyscale dilation, using either a structuring element,
or a footprint corresponding to a flat structuring element.

Grayscale dilation is a mathematical morphology operation. For the
simple case of a full and flat structuring element, it can be viewed
as a maximum filter over a sliding window.

Parameters
----------
input : array_like
    Array over which the grayscale dilation is to be computed.
size : tuple of ints
    Shape of a flat and full structuring element used for the grayscale
    dilation. Optional if `footprint` or `structure` is provided.
footprint : array of ints, optional
    Positions of non-infinite elements of a flat structuring element
    used for the grayscale dilation. Non-zero values give the set of
    neighbors of the center over which the maximum is chosen.
structure : array of ints, optional
    Structuring element used for the grayscale dilation. `structure`
    may be a non-flat structuring element.
output : array, optional
    An array used for storing the ouput of the dilation may be provided.
mode : {'reflect','constant','nearest','mirror', 'wrap'}, optional
    The `mode` parameter determines how the array borders are
    handled, where `cval` is the value when mode is equal to
    'constant'. Default is 'reflect'
cval : scalar, optional
    Value to fill past edges of input if `mode` is 'constant'. Default
    is 0.0.
origin : scalar, optional
    The `origin` parameter controls the placement of the filter.
    Default 0

Returns
-------
grey_dilation : ndarray
    Grayscale dilation of `input`.

See also
--------
binary_dilation, grey_erosion, grey_closing, grey_opening
generate_binary_structure, ndimage.maximum_filter

Notes
-----
The grayscale dilation of an image input by a structuring element s defined
over a domain E is given by:

(input+s)(x) = max {input(y) + s(x-y), for y in E}

In particular, for structuring elements defined as
s(y) = 0 for y in E, the grayscale dilation computes the maximum of the
input image inside a sliding window defined by E.

Grayscale dilation [1]_ is a *mathematical morphology* operation [2]_.

References
----------
.. [1] http://en.wikipedia.org/wiki/Dilation_%28morphology%29
.. [2] http://en.wikipedia.org/wiki/Mathematical_morphology

Examples
--------
>>> a = np.zeros((7,7), dtype=np.int)
>>> a[2:5, 2:5] = 1
>>> a[4,4] = 2; a[2,3] = 3
>>> a
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 3, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 2, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]])
>>> ndimage.grey_dilation(a, size=(3,3))
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 1, 3, 3, 3, 1, 0],
       [0, 1, 3, 3, 3, 1, 0],
       [0, 1, 3, 3, 3, 2, 0],
       [0, 1, 1, 2, 2, 2, 0],
       [0, 1, 1, 2, 2, 2, 0],
       [0, 0, 0, 0, 0, 0, 0]])
>>> ndimage.grey_dilation(a, footprint=np.ones((3,3)))
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 1, 3, 3, 3, 1, 0],
       [0, 1, 3, 3, 3, 1, 0],
       [0, 1, 3, 3, 3, 2, 0],
       [0, 1, 1, 2, 2, 2, 0],
       [0, 1, 1, 2, 2, 2, 0],
       [0, 0, 0, 0, 0, 0, 0]])
>>> s = ndimage.generate_binary_structure(2,1)
>>> s
array([[False,  True, False],
       [ True,  True,  True],
       [False,  True, False]], dtype=bool)
>>> ndimage.grey_dilation(a, footprint=s)
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 3, 1, 0, 0],
       [0, 1, 3, 3, 3, 1, 0],
       [0, 1, 1, 3, 2, 1, 0],
       [0, 1, 1, 2, 2, 2, 0],
       [0, 0, 1, 1, 2, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]])
>>> ndimage.grey_dilation(a, size=(3,3), structure=np.ones((3,3)))
array([[1, 1, 1, 1, 1, 1, 1],
       [1, 2, 4, 4, 4, 2, 1],
       [1, 2, 4, 4, 4, 2, 1],
       [1, 2, 4, 4, 4, 3, 1],
       [1, 2, 2, 3, 3, 3, 1],
       [1, 2, 2, 3, 3, 3, 1],
       [1, 1, 1, 1, 1, 1, 1]])


def grey_opening(input, size=None, footprint=None, structure=None,<EOL>output=None, mode="<STR_LIT>", cval=<NUM_LIT:0.0>, origin=<NUM_LIT:0>):

tmp = grey_erosion(input, size, footprint, structure, None, mode,<EOL>cval, origin)<EOL>return grey_dilation(tmp, size, footprint, structure, output, mode,<EOL>cval, origin)<EOL>

Multi-dimensional greyscale opening.

A greyscale opening consists in the succession of a greyscale erosion,
and a greyscale dilation.

Parameters
----------
input : array_like
    Array over which the grayscale opening is to be computed.
size : tuple of ints
    Shape of a flat and full structuring element used for the grayscale
    opening. Optional if `footprint` or `structure` is provided.
footprint : array of ints, optional
    Positions of non-infinite elements of a flat structuring element
    used for the grayscale opening.
structure : array of ints, optional
    Structuring element used for the grayscale opening. `structure`
    may be a non-flat structuring element.
output : array, optional
    An array used for storing the ouput of the opening may be provided.
mode : {'reflect', 'constant', 'nearest', 'mirror', 'wrap'}, optional
    The `mode` parameter determines how the array borders are
    handled, where `cval` is the value when mode is equal to
    'constant'. Default is 'reflect'
cval : scalar, optional
    Value to fill past edges of input if `mode` is 'constant'. Default
    is 0.0.
origin : scalar, optional
    The `origin` parameter controls the placement of the filter.
    Default 0

Returns
-------
grey_opening : ndarray
    Result of the grayscale opening of `input` with `structure`.

See also
--------
binary_opening, grey_dilation, grey_erosion, grey_closing
generate_binary_structure

Notes
-----
The action of a grayscale opening with a flat structuring element amounts
to smoothen high local maxima, whereas binary opening erases small objects.

References
----------
.. [1] http://en.wikipedia.org/wiki/Mathematical_morphology

Examples
--------
>>> a = np.arange(36).reshape((6,6))
>>> a[3, 3] = 50
>>> a
array([[ 0,  1,  2,  3,  4,  5],
       [ 6,  7,  8,  9, 10, 11],
       [12, 13, 14, 15, 16, 17],
       [18, 19, 20, 50, 22, 23],
       [24, 25, 26, 27, 28, 29],
       [30, 31, 32, 33, 34, 35]])
>>> ndimage.grey_opening(a, size=(3,3))
array([[ 0,  1,  2,  3,  4,  4],
       [ 6,  7,  8,  9, 10, 10],
       [12, 13, 14, 15, 16, 16],
       [18, 19, 20, 22, 22, 22],
       [24, 25, 26, 27, 28, 28],
       [24, 25, 26, 27, 28, 28]])
>>> # Note that the local maximum a[3,3] has disappeared


def grey_closing(input, size=None, footprint=None, structure=None,<EOL>output=None, mode="<STR_LIT>", cval=<NUM_LIT:0.0>, origin=<NUM_LIT:0>):

tmp = grey_dilation(input, size, footprint, structure, None, mode,<EOL>cval, origin)<EOL>return grey_erosion(tmp, size, footprint, structure, output, mode,<EOL>cval, origin)<EOL>

Multi-dimensional greyscale closing.

A greyscale closing consists in the succession of a greyscale dilation,
and a greyscale erosion.

Parameters
----------
input : array_like
    Array over which the grayscale closing is to be computed.
size : tuple of ints
    Shape of a flat and full structuring element used for the grayscale
    closing. Optional if `footprint` or `structure` is provided.
footprint : array of ints, optional
    Positions of non-infinite elements of a flat structuring element
    used for the grayscale closing.
structure : array of ints, optional
    Structuring element used for the grayscale closing. `structure`
    may be a non-flat structuring element.
output : array, optional
    An array used for storing the ouput of the closing may be provided.
mode : {'reflect', 'constant', 'nearest', 'mirror', 'wrap'}, optional
    The `mode` parameter determines how the array borders are
    handled, where `cval` is the value when mode is equal to
    'constant'. Default is 'reflect'
cval : scalar, optional
    Value to fill past edges of input if `mode` is 'constant'. Default
    is 0.0.
origin : scalar, optional
    The `origin` parameter controls the placement of the filter.
    Default 0

Returns
-------
grey_closing : ndarray
    Result of the grayscale closing of `input` with `structure`.

See also
--------
binary_closing, grey_dilation, grey_erosion, grey_opening,
generate_binary_structure

Notes
-----
The action of a grayscale closing with a flat structuring element amounts
to smoothen deep local minima, whereas binary closing fills small holes.

References
----------
.. [1] http://en.wikipedia.org/wiki/Mathematical_morphology

Examples
--------
>>> a = np.arange(36).reshape((6,6))
>>> a[3,3] = 0
>>> a
array([[ 0,  1,  2,  3,  4,  5],
       [ 6,  7,  8,  9, 10, 11],
       [12, 13, 14, 15, 16, 17],
       [18, 19, 20,  0, 22, 23],
       [24, 25, 26, 27, 28, 29],
       [30, 31, 32, 33, 34, 35]])
>>> ndimage.grey_closing(a, size=(3,3))
array([[ 7,  7,  8,  9, 10, 11],
       [ 7,  7,  8,  9, 10, 11],
       [13, 13, 14, 15, 16, 17],
       [19, 19, 20, 20, 22, 23],
       [25, 25, 26, 27, 28, 29],
       [31, 31, 32, 33, 34, 35]])
>>> # Note that the local minimum a[3,3] has disappeared


def morphological_gradient(input, size=None, footprint=None,<EOL>structure=None, output=None, mode="<STR_LIT>",<EOL>cval=<NUM_LIT:0.0>, origin=<NUM_LIT:0>):

tmp = grey_dilation(input, size, footprint, structure, None, mode,<EOL>cval, origin)<EOL>if isinstance(output, numpy.ndarray):<EOL><INDENT>grey_erosion(input, size, footprint, structure, output, mode,<EOL>cval, origin)<EOL>return numpy.subtract(tmp, output, output)<EOL><DEDENT>else:<EOL><INDENT>return (tmp - grey_erosion(input, size, footprint, structure,<EOL>None, mode, cval, origin))<EOL><DEDENT>

Multi-dimensional morphological gradient.

The morphological gradient is calculated as the difference between a
dilation and an erosion of the input with a given structuring element.

Parameters
----------
input : array_like
    Array over which to compute the morphlogical gradient.
size : tuple of ints
    Shape of a flat and full structuring element used for the mathematical
    morphology operations. Optional if `footprint` or `structure` is
    provided. A larger `size` yields a more blurred gradient.
footprint : array of ints, optional
    Positions of non-infinite elements of a flat structuring element
    used for the morphology operations. Larger footprints
    give a more blurred morphological gradient.
structure : array of ints, optional
    Structuring element used for the morphology operations.
    `structure` may be a non-flat structuring element.
output : array, optional
    An array used for storing the ouput of the morphological gradient
    may be provided.
mode : {'reflect', 'constant', 'nearest', 'mirror', 'wrap'}, optional
    The `mode` parameter determines how the array borders are
    handled, where `cval` is the value when mode is equal to
    'constant'. Default is 'reflect'
cval : scalar, optional
    Value to fill past edges of input if `mode` is 'constant'. Default
    is 0.0.
origin : scalar, optional
    The `origin` parameter controls the placement of the filter.
    Default 0

Returns
-------
morphological_gradient : ndarray
    Morphological gradient of `input`.

See also
--------
grey_dilation, grey_erosion, ndimage.gaussian_gradient_magnitude

Notes
-----
For a flat structuring element, the morphological gradient
computed at a given point corresponds to the maximal difference
between elements of the input among the elements covered by the
structuring element centered on the point.

References
----------
.. [1] http://en.wikipedia.org/wiki/Mathematical_morphology

Examples
--------
>>> a = np.zeros((7,7), dtype=np.int)
>>> a[2:5, 2:5] = 1
>>> ndimage.morphological_gradient(a, size=(3,3))
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 1, 1, 1, 1, 1, 0],
       [0, 1, 1, 1, 1, 1, 0],
       [0, 1, 1, 0, 1, 1, 0],
       [0, 1, 1, 1, 1, 1, 0],
       [0, 1, 1, 1, 1, 1, 0],
       [0, 0, 0, 0, 0, 0, 0]])
>>> # The morphological gradient is computed as the difference
>>> # between a dilation and an erosion
>>> ndimage.grey_dilation(a, size=(3,3)) -\\
...  ndimage.grey_erosion(a, size=(3,3))
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 1, 1, 1, 1, 1, 0],
       [0, 1, 1, 1, 1, 1, 0],
       [0, 1, 1, 0, 1, 1, 0],
       [0, 1, 1, 1, 1, 1, 0],
       [0, 1, 1, 1, 1, 1, 0],
       [0, 0, 0, 0, 0, 0, 0]])
>>> a = np.zeros((7,7), dtype=np.int)
>>> a[2:5, 2:5] = 1
>>> a[4,4] = 2; a[2,3] = 3
>>> a
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 3, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 2, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]])
>>> ndimage.morphological_gradient(a, size=(3,3))
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 1, 3, 3, 3, 1, 0],
       [0, 1, 3, 3, 3, 1, 0],
       [0, 1, 3, 2, 3, 2, 0],
       [0, 1, 1, 2, 2, 2, 0],
       [0, 1, 1, 2, 2, 2, 0],
       [0, 0, 0, 0, 0, 0, 0]])


def morphological_laplace(input, size=None, footprint=None,<EOL>structure=None, output=None,<EOL>mode="<STR_LIT>", cval=<NUM_LIT:0.0>, origin=<NUM_LIT:0>):

tmp1 = grey_dilation(input, size, footprint, structure, None, mode,<EOL>cval, origin)<EOL>if isinstance(output, numpy.ndarray):<EOL><INDENT>grey_erosion(input, size, footprint, structure, output, mode,<EOL>cval, origin)<EOL>numpy.add(tmp1, output, output)<EOL>numpy.subtract(output, input, output)<EOL>return numpy.subtract(output, input, output)<EOL><DEDENT>else:<EOL><INDENT>tmp2 = grey_erosion(input, size, footprint, structure, None, mode,<EOL>cval, origin)<EOL>numpy.add(tmp1, tmp2, tmp2)<EOL>numpy.subtract(tmp2, input, tmp2)<EOL>numpy.subtract(tmp2, input, tmp2)<EOL>return tmp2<EOL><DEDENT>

Multi-dimensional morphological laplace.

Parameters
----------
input : array_like
    Input.
size : int or sequence of ints, optional
    See `structure`.
footprint : bool or ndarray, optional
    See `structure`.
structure : structure
    Either `size`, `footprint`, or the `structure` must be provided.
output : ndarray
    An output array can optionally be provided.
mode : {'reflect','constant','nearest','mirror', 'wrap'}, optional
    The mode parameter determines how the array borders are handled.
    For 'constant' mode, values beyond borders are set to be `cval`.
    Default is 'reflect'.
cval : scalar, optional
    Value to fill past edges of input if mode is 'constant'.
    Default is 0.0
origin : origin
    The origin parameter controls the placement of the filter.

Returns
-------
morphological_laplace : ndarray
    Output


def white_tophat(input, size=None, footprint=None, structure=None,<EOL>output=None, mode="<STR_LIT>", cval=<NUM_LIT:0.0>, origin=<NUM_LIT:0>):

tmp = grey_erosion(input, size, footprint, structure, None, mode,<EOL>cval, origin)<EOL>if isinstance(output, numpy.ndarray):<EOL><INDENT>grey_dilation(tmp, size, footprint, structure, output, mode, cval,<EOL>origin)<EOL>return numpy.subtract(input, output, output)<EOL><DEDENT>else:<EOL><INDENT>tmp = grey_dilation(tmp, size, footprint, structure, None, mode,<EOL>cval, origin)<EOL>return input - tmp<EOL><DEDENT>

Multi-dimensional white tophat filter.

Parameters
----------
input : array_like
    Input.
size : tuple of ints
    Shape of a flat and full structuring element used for the filter.
    Optional if `footprint` or `structure` is provided.
footprint : array of ints, optional
    Positions of elements of a flat structuring element
    used for the white tophat filter.
structure : array of ints, optional
    Structuring element used for the filter. `structure`
    may be a non-flat structuring element.
output : array, optional
    An array used for storing the output of the filter may be provided.
mode : {'reflect', 'constant', 'nearest', 'mirror', 'wrap'}, optional
    The `mode` parameter determines how the array borders are
    handled, where `cval` is the value when mode is equal to
    'constant'. Default is 'reflect'
cval : scalar, optional
    Value to fill past edges of input if `mode` is 'constant'.
    Default is 0.0.
origin : scalar, optional
    The `origin` parameter controls the placement of the filter.
    Default is 0.

Returns
-------
output : ndarray
    Result of the filter of `input` with `structure`.

See also
--------
black_tophat


def black_tophat(input, size=None, footprint=None,<EOL>structure=None, output=None, mode="<STR_LIT>",<EOL>cval=<NUM_LIT:0.0>, origin=<NUM_LIT:0>):

tmp = grey_dilation(input, size, footprint, structure, None, mode,<EOL>cval, origin)<EOL>if isinstance(output, numpy.ndarray):<EOL><INDENT>grey_erosion(tmp, size, footprint, structure, output, mode, cval,<EOL>origin)<EOL>return numpy.subtract(output, input, output)<EOL><DEDENT>else:<EOL><INDENT>tmp = grey_erosion(tmp, size, footprint, structure, None, mode,<EOL>cval, origin)<EOL>return tmp - input<EOL><DEDENT>

Multi-dimensional black tophat filter.

Parameters
----------
input : array_like
    Input.
size : tuple of ints
    Shape of a flat and full structuring element used for the filter.
    Optional if `footprint` or `structure` is provided.
footprint : array of ints, optional
    Positions of non-infinite elements of a flat structuring element
    used for the black tophat filter.
structure : array of ints, optional
    Structuring element used for the filter. `structure`
    may be a non-flat structuring element.
output : array, optional
    An array used for storing the output of the filter may be provided.
mode : {'reflect', 'constant', 'nearest', 'mirror', 'wrap'}, optional
    The `mode` parameter determines how the array borders are
    handled, where `cval` is the value when mode is equal to
    'constant'. Default is 'reflect'
cval : scalar, optional
    Value to fill past edges of input if `mode` is 'constant'. Default
    is 0.0.
origin : scalar, optional
    The `origin` parameter controls the placement of the filter.
    Default 0

Returns
-------
black_tophat : ndarray
    Result of the filter of `input` with `structure`.

See also
--------
white_tophat, grey_opening, grey_closing


def distance_transform_bf(input, metric="<STR_LIT>", sampling=None,<EOL>return_distances=True, return_indices=False,<EOL>distances=None, indices=None):

if (not return_distances) and (not return_indices):<EOL><INDENT>msg = '<STR_LIT>'<EOL>raise RuntimeError(msg)<EOL><DEDENT>tmp1 = numpy.asarray(input) != <NUM_LIT:0><EOL>struct = generate_binary_structure(tmp1.ndim, tmp1.ndim)<EOL>tmp2 = binary_dilation(tmp1, struct)<EOL>tmp2 = numpy.logical_xor(tmp1, tmp2)<EOL>tmp1 = tmp1.astype(numpy.int8) - tmp2.astype(numpy.int8)<EOL>metric = metric.lower()<EOL>if metric == '<STR_LIT>':<EOL><INDENT>metric = <NUM_LIT:1><EOL><DEDENT>elif metric in ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>metric = <NUM_LIT:2><EOL><DEDENT>elif metric == '<STR_LIT>':<EOL><INDENT>metric = <NUM_LIT:3><EOL><DEDENT>else:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>if sampling is not None:<EOL><INDENT>sampling = _ni_support._normalize_sequence(sampling, tmp1.ndim)<EOL>sampling = numpy.asarray(sampling, dtype=numpy.float64)<EOL>if not sampling.flags.contiguous:<EOL><INDENT>sampling = sampling.copy()<EOL><DEDENT><DEDENT>if return_indices:<EOL><INDENT>ft = numpy.zeros(tmp1.shape, dtype=numpy.int32)<EOL><DEDENT>else:<EOL><INDENT>ft = None<EOL><DEDENT>if return_distances:<EOL><INDENT>if distances is None:<EOL><INDENT>if metric == <NUM_LIT:1>:<EOL><INDENT>dt = numpy.zeros(tmp1.shape, dtype=numpy.float64)<EOL><DEDENT>else:<EOL><INDENT>dt = numpy.zeros(tmp1.shape, dtype=numpy.uint32)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if distances.shape != tmp1.shape:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>if metric == <NUM_LIT:1>:<EOL><INDENT>if distances.dtype.type != numpy.float64:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if distances.dtype.type != numpy.uint32:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT><DEDENT>dt = distances<EOL><DEDENT><DEDENT>else:<EOL><INDENT>dt = None<EOL><DEDENT>_nd_image.distance_transform_bf(tmp1, metric, sampling, dt, ft)<EOL>if return_indices:<EOL><INDENT>if isinstance(indices, numpy.ndarray):<EOL><INDENT>if indices.dtype.type != numpy.int32:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>if indices.shape != (tmp1.ndim,) + tmp1.shape:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>tmp2 = indices<EOL><DEDENT>else:<EOL><INDENT>tmp2 = numpy.indices(tmp1.shape, dtype=numpy.int32)<EOL><DEDENT>ft = numpy.ravel(ft)<EOL>for ii in range(tmp2.shape[<NUM_LIT:0>]):<EOL><INDENT>rtmp = numpy.ravel(tmp2[ii, ...])[ft]<EOL>rtmp.shape = tmp1.shape<EOL>tmp2[ii, ...] = rtmp<EOL><DEDENT>ft = tmp2<EOL><DEDENT>result = []<EOL>if return_distances and not isinstance(distances, numpy.ndarray):<EOL><INDENT>result.append(dt)<EOL><DEDENT>if return_indices and not isinstance(indices, numpy.ndarray):<EOL><INDENT>result.append(ft)<EOL><DEDENT>if len(result) == <NUM_LIT:2>:<EOL><INDENT>return tuple(result)<EOL><DEDENT>elif len(result) == <NUM_LIT:1>:<EOL><INDENT>return result[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>

Distance transform function by a brute force algorithm.

This function calculates the distance transform of the `input`, by
replacing each background element (zero values), with its
shortest distance to the foreground (any element non-zero).

In addition to the distance transform, the feature transform can
be calculated. In this case the index of the closest background
element is returned along the first axis of the result.

Parameters
----------
input : array_like
    Input
metric : str, optional
    Three types of distance metric are supported: 'euclidean', 'taxicab'
    and 'chessboard'.
sampling : {int, sequence of ints}, optional
    This parameter is only used in the case of the euclidean `metric`
    distance transform.

    The sampling along each axis can be given by the `sampling` parameter
    which should be a sequence of length equal to the input rank, or a
    single number in which the `sampling` is assumed to be equal along all
    axes.
return_distances : bool, optional
    The `return_distances` flag can be used to indicate if the distance
    transform is returned.

    The default is True.
return_indices : bool, optional
    The `return_indices` flags can be used to indicate if the feature
    transform is returned.

    The default is False.
distances : float64 ndarray, optional
    Optional output array to hold distances (if `return_distances` is
    True).
indices : int64 ndarray, optional
    Optional output array to hold indices (if `return_indices` is True).

Returns
-------
distances : ndarray
    Distance array if `return_distances` is True.
indices : ndarray
    Indices array if `return_indices` is True.

Notes
-----
This function employs a slow brute force algorithm, see also the
function distance_transform_cdt for more efficient taxicab and
chessboard algorithms.


def distance_transform_cdt(input, metric='<STR_LIT>',<EOL>return_distances=True, return_indices=False,<EOL>distances=None, indices=None):

if (not return_distances) and (not return_indices):<EOL><INDENT>msg = '<STR_LIT>'<EOL>raise RuntimeError(msg)<EOL><DEDENT>ft_inplace = isinstance(indices, numpy.ndarray)<EOL>dt_inplace = isinstance(distances, numpy.ndarray)<EOL>input = numpy.asarray(input)<EOL>if metric in ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>rank = input.ndim<EOL>metric = generate_binary_structure(rank, <NUM_LIT:1>)<EOL><DEDENT>elif metric == '<STR_LIT>':<EOL><INDENT>rank = input.ndim<EOL>metric = generate_binary_structure(rank, rank)<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>metric = numpy.asarray(metric)<EOL><DEDENT>except:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>for s in metric.shape:<EOL><INDENT>if s != <NUM_LIT:3>:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>if not metric.flags.contiguous:<EOL><INDENT>metric = metric.copy()<EOL><DEDENT>if dt_inplace:<EOL><INDENT>if distances.dtype.type != numpy.int32:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>if distances.shape != input.shape:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>dt = distances<EOL>dt[...] = numpy.where(input, -<NUM_LIT:1>, <NUM_LIT:0>).astype(numpy.int32)<EOL><DEDENT>else:<EOL><INDENT>dt = numpy.where(input, -<NUM_LIT:1>, <NUM_LIT:0>).astype(numpy.int32)<EOL><DEDENT>rank = dt.ndim<EOL>if return_indices:<EOL><INDENT>sz = numpy.product(dt.shape,axis=<NUM_LIT:0>)<EOL>ft = numpy.arange(sz, dtype=numpy.int32)<EOL>ft.shape = dt.shape<EOL><DEDENT>else:<EOL><INDENT>ft = None<EOL><DEDENT>_nd_image.distance_transform_op(metric, dt, ft)<EOL>dt = dt[tuple([slice(None, None, -<NUM_LIT:1>)] * rank)]<EOL>if return_indices:<EOL><INDENT>ft = ft[tuple([slice(None, None, -<NUM_LIT:1>)] * rank)]<EOL><DEDENT>_nd_image.distance_transform_op(metric, dt, ft)<EOL>dt = dt[tuple([slice(None, None, -<NUM_LIT:1>)] * rank)]<EOL>if return_indices:<EOL><INDENT>ft = ft[tuple([slice(None, None, -<NUM_LIT:1>)] * rank)]<EOL>ft = numpy.ravel(ft)<EOL>if ft_inplace:<EOL><INDENT>if indices.dtype.type != numpy.int32:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>if indices.shape != (dt.ndim,) + dt.shape:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>tmp = indices<EOL><DEDENT>else:<EOL><INDENT>tmp = numpy.indices(dt.shape, dtype=numpy.int32)<EOL><DEDENT>for ii in range(tmp.shape[<NUM_LIT:0>]):<EOL><INDENT>rtmp = numpy.ravel(tmp[ii, ...])[ft]<EOL>rtmp.shape = dt.shape<EOL>tmp[ii, ...] = rtmp<EOL><DEDENT>ft = tmp<EOL><DEDENT>result = []<EOL>if return_distances and not dt_inplace:<EOL><INDENT>result.append(dt)<EOL><DEDENT>if return_indices and not ft_inplace:<EOL><INDENT>result.append(ft)<EOL><DEDENT>if len(result) == <NUM_LIT:2>:<EOL><INDENT>return tuple(result)<EOL><DEDENT>elif len(result) == <NUM_LIT:1>:<EOL><INDENT>return result[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>

Distance transform for chamfer type of transforms.

Parameters
----------
input : array_like
    Input
metric : {'chessboard', 'taxicab'}, optional
    The `metric` determines the type of chamfering that is done. If the
    `metric` is equal to 'taxicab' a structure is generated using
    generate_binary_structure with a squared distance equal to 1. If
    the `metric` is equal to 'chessboard', a `metric` is generated
    using generate_binary_structure with a squared distance equal to
    the dimensionality of the array. These choices correspond to the
    common interpretations of the 'taxicab' and the 'chessboard'
    distance metrics in two dimensions.

    The default for `metric` is 'chessboard'.
return_distances, return_indices : bool, optional
    The `return_distances`, and `return_indices` flags can be used to
    indicate if the distance transform, the feature transform, or both
    must be returned.

    If the feature transform is returned (``return_indices=True``),
    the index of the closest background element is returned along
    the first axis of the result.

    The `return_distances` default is True, and the
    `return_indices` default is False.
distances, indices : ndarrays of int32, optional
    The `distances` and `indices` arguments can be used to give optional
    output arrays that must be the same shape as `input`.


def distance_transform_edt(input, sampling=None,<EOL>return_distances=True, return_indices=False,<EOL>distances=None, indices=None):

if (not return_distances) and (not return_indices):<EOL><INDENT>msg = '<STR_LIT>'<EOL>raise RuntimeError(msg)<EOL><DEDENT>ft_inplace = isinstance(indices, numpy.ndarray)<EOL>dt_inplace = isinstance(distances, numpy.ndarray)<EOL>input = numpy.atleast_1d(numpy.where(input, <NUM_LIT:1>, <NUM_LIT:0>).astype(numpy.int8))<EOL>if sampling is not None:<EOL><INDENT>sampling = _ni_support._normalize_sequence(sampling, input.ndim)<EOL>sampling = numpy.asarray(sampling, dtype=numpy.float64)<EOL>if not sampling.flags.contiguous:<EOL><INDENT>sampling = sampling.copy()<EOL><DEDENT><DEDENT>if ft_inplace:<EOL><INDENT>ft = indices<EOL>if ft.shape != (input.ndim,) + input.shape:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>if ft.dtype.type != numpy.int32:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>ft = numpy.zeros((input.ndim,) + input.shape,<EOL>dtype=numpy.int32)<EOL><DEDENT>_nd_image.euclidean_feature_transform(input, sampling, ft)<EOL>if return_distances:<EOL><INDENT>dt = ft - numpy.indices(input.shape, dtype=ft.dtype)<EOL>dt = dt.astype(numpy.float64)<EOL>if sampling is not None:<EOL><INDENT>for ii in range(len(sampling)):<EOL><INDENT>dt[ii, ...] *= sampling[ii]<EOL><DEDENT><DEDENT>numpy.multiply(dt, dt, dt)<EOL>if dt_inplace:<EOL><INDENT>dt = numpy.add.reduce(dt, axis=<NUM_LIT:0>)<EOL>if distances.shape != dt.shape:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>if distances.dtype.type != numpy.float64:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>numpy.sqrt(dt, distances)<EOL><DEDENT>else:<EOL><INDENT>dt = numpy.add.reduce(dt, axis=<NUM_LIT:0>)<EOL>dt = numpy.sqrt(dt)<EOL><DEDENT><DEDENT>result = []<EOL>if return_distances and not dt_inplace:<EOL><INDENT>result.append(dt)<EOL><DEDENT>if return_indices and not ft_inplace:<EOL><INDENT>result.append(ft)<EOL><DEDENT>if len(result) == <NUM_LIT:2>:<EOL><INDENT>return tuple(result)<EOL><DEDENT>elif len(result) == <NUM_LIT:1>:<EOL><INDENT>return result[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>

Exact euclidean distance transform.

In addition to the distance transform, the feature transform can
be calculated. In this case the index of the closest background
element is returned along the first axis of the result.

Parameters
----------
input : array_like
    Input data to transform. Can be any type but will be converted
    into binary: 1 wherever input equates to True, 0 elsewhere.
sampling : float or int, or sequence of same, optional
    Spacing of elements along each dimension. If a sequence, must be of
    length equal to the input rank; if a single number, this is used for
    all axes. If not specified, a grid spacing of unity is implied.
return_distances : bool, optional
    Whether to return distance matrix. At least one of
    return_distances/return_indices must be True. Default is True.
return_indices : bool, optional
    Whether to return indices matrix. Default is False.
distance : ndarray, optional
    Used for output of distance array, must be of type float64.
indices : ndarray, optional
    Used for output of indices, must be of type int32.

Returns
-------
distance_transform_edt : ndarray or list of ndarrays
    Either distance matrix, index matrix, or a list of the two,
    depending on `return_x` flags and `distance` and `indices`
    input parameters.

Notes
-----
The euclidean distance transform gives values of the euclidean
distance::

                n
  y_i = sqrt(sum (x[i]-b[i])**2)
                i

where b[i] is the background point (value 0) with the smallest
Euclidean distance to input points x[i], and n is the
number of dimensions.

Examples
--------
>>> a = np.array(([0,1,1,1,1],
                  [0,0,1,1,1],
                  [0,1,1,1,1],
                  [0,1,1,1,0],
                  [0,1,1,0,0]))
>>> from scipy import ndimage
>>> ndimage.distance_transform_edt(a)
array([[ 0.    ,  1.    ,  1.4142,  2.2361,  3.    ],
       [ 0.    ,  0.    ,  1.    ,  2.    ,  2.    ],
       [ 0.    ,  1.    ,  1.4142,  1.4142,  1.    ],
       [ 0.    ,  1.    ,  1.4142,  1.    ,  0.    ],
       [ 0.    ,  1.    ,  1.    ,  0.    ,  0.    ]])

With a sampling of 2 units along x, 1 along y:

>>> ndimage.distance_transform_edt(a, sampling=[2,1])
array([[ 0.    ,  1.    ,  2.    ,  2.8284,  3.6056],
       [ 0.    ,  0.    ,  1.    ,  2.    ,  3.    ],
       [ 0.    ,  1.    ,  2.    ,  2.2361,  2.    ],
       [ 0.    ,  1.    ,  2.    ,  1.    ,  0.    ],
       [ 0.    ,  1.    ,  1.    ,  0.    ,  0.    ]])

Asking for indices as well:

>>> edt, inds = ndimage.distance_transform_edt(a, return_indices=True)
>>> inds
array([[[0, 0, 1, 1, 3],
        [1, 1, 1, 1, 3],
        [2, 2, 1, 3, 3],
        [3, 3, 4, 4, 3],
        [4, 4, 4, 4, 4]],
       [[0, 0, 1, 1, 4],
        [0, 1, 1, 1, 4],
        [0, 0, 1, 4, 4],
        [0, 0, 3, 3, 4],
        [0, 0, 3, 3, 4]]])

With arrays provided for inplace outputs:

>>> indices = np.zeros(((np.ndim(a),) + a.shape), dtype=np.int32)
>>> ndimage.distance_transform_edt(a, return_indices=True, indices=indices)
array([[ 0.    ,  1.    ,  1.4142,  2.2361,  3.    ],
       [ 0.    ,  0.    ,  1.    ,  2.    ,  2.    ],
       [ 0.    ,  1.    ,  1.4142,  1.4142,  1.    ],
       [ 0.    ,  1.    ,  1.4142,  1.    ,  0.    ],
       [ 0.    ,  1.    ,  1.    ,  0.    ,  0.    ]])
>>> indices
array([[[0, 0, 1, 1, 3],
        [1, 1, 1, 1, 3],
        [2, 2, 1, 3, 3],
        [3, 3, 4, 4, 3],
        [4, 4, 4, 4, 4]],
       [[0, 0, 1, 1, 4],
        [0, 1, 1, 1, 4],
        [0, 0, 1, 4, 4],
        [0, 0, 3, 3, 4],
        [0, 0, 3, 3, 4]]])


def imread(fname, flatten=False, mode=None):

try:<EOL><INDENT>from PIL import Image<EOL><DEDENT>except ImportError:<EOL><INDENT>raise ImportError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>im = Image.open(fname)<EOL>if mode:<EOL><INDENT>im = im.convert(mode)<EOL><DEDENT>if flatten:<EOL><INDENT>im = im.convert('<STR_LIT:F>')<EOL><DEDENT>result = array(im)<EOL>return result<EOL>

Read an image from a file as an array.

Parameters
----------
fname : str
    Image file name, e.g. ``test.jpg``, or a file object.
flatten : bool, optional
    If true, convert the output to grey-scale. Default is False.
mode : str, optional
    mode to convert image to, e.g. ``RGB``.

Returns
-------
img_array : ndarray
    The different colour bands/channels are stored in the
    third dimension, such that a grey-image is MxN, an
    RGB-image MxNx3 and an RGBA-image MxNx4.

Raises
------
ImportError
    If the Python Imaging Library (PIL) can not be imported.


return _np.asanyarray(C) + zero_Celsius<EOL>

Convert Celsius to Kelvin

Parameters
----------
C : array_like
    Celsius temperature(s) to be converted.

Returns
-------
K : float or array of floats
    Equivalent Kelvin temperature(s).

Notes
-----
Computes ``K = C + zero_Celsius`` where `zero_Celsius` = 273.15, i.e.,
(the absolute value of) temperature "absolute zero" as measured in Celsius.

Examples
--------
>>> from scipy.constants.constants import C2K
>>> C2K(_np.array([-40, 40.0]))
array([ 233.15,  313.15])


return _np.asanyarray(K) - zero_Celsius<EOL>

Convert Kelvin to Celsius

Parameters
----------
K : array_like
    Kelvin temperature(s) to be converted.

Returns
-------
C : float or array of floats
    Equivalent Celsius temperature(s).

Notes
-----
Computes ``C = K - zero_Celsius`` where `zero_Celsius` = 273.15, i.e.,
(the absolute value of) temperature "absolute zero" as measured in Celsius.

Examples
--------
>>> from scipy.constants.constants import K2C
>>> K2C(_np.array([233.15, 313.15]))
array([-40.,  40.])


return (_np.asanyarray(F) - <NUM_LIT:32>) / <NUM_LIT><EOL>

Convert Fahrenheit to Celsius

Parameters
----------
F : array_like
    Fahrenheit temperature(s) to be converted.

Returns
-------
C : float or array of floats
    Equivalent Celsius temperature(s).

Notes
-----
Computes ``C = (F - 32) / 1.8``.

Examples
--------
>>> from scipy.constants.constants import F2C
>>> F2C(_np.array([-40, 40.0]))
array([-40.        ,   4.44444444])


return <NUM_LIT> * _np.asanyarray(C) + <NUM_LIT:32><EOL>

Convert Celsius to Fahrenheit

Parameters
----------
C : array_like
    Celsius temperature(s) to be converted.

Returns
-------
F : float or array of floats
    Equivalent Fahrenheit temperature(s).

Notes
-----
Computes ``F = 1.8 * C + 32``.

Examples
--------
>>> from scipy.constants.constants import C2F
>>> C2F(_np.array([-40, 40.0]))
array([ -40.,  104.])


return C2K(F2C(_np.asanyarray(F)))<EOL>

Convert Fahrenheit to Kelvin

Parameters
----------
F : array_like
    Fahrenheit temperature(s) to be converted.

Returns
-------
K : float or array of floats
    Equivalent Kelvin temperature(s).

Notes
-----
Computes ``K = (F - 32)/1.8 + zero_Celsius`` where `zero_Celsius` =
273.15, i.e., (the absolute value of) temperature "absolute zero" as
measured in Celsius.

Examples
--------
>>> from scipy.constants.constants import F2K
>>> F2K(_np.array([-40, 104]))
array([ 233.15,  313.15])


return C2F(K2C(_np.asanyarray(K)))<EOL>

Convert Kelvin to Fahrenheit

Parameters
----------
K : array_like
    Kelvin temperature(s) to be converted.

Returns
-------
F : float or array of floats
    Equivalent Fahrenheit temperature(s).

Notes
-----
Computes ``F = 1.8 * (K - zero_Celsius) + 32`` where `zero_Celsius` =
273.15, i.e., (the absolute value of) temperature "absolute zero" as
measured in Celsius.

Examples
--------
>>> from scipy.constants.constants import K2F
>>> K2F(_np.array([233.15,  313.15]))
array([ -40.,  104.])


return _np.asanyarray(c) / lambda_<EOL>

Convert wavelength to optical frequency

Parameters
----------
lambda : array_like
    Wavelength(s) to be converted.

Returns
-------
nu : float or array of floats
    Equivalent optical frequency.

Notes
-----
Computes ``nu = c / lambda`` where c = 299792458.0, i.e., the
(vacuum) speed of light in meters/second.

Examples
--------
>>> from scipy.constants.constants import lambda2nu
>>> lambda2nu(_np.array((1, speed_of_light)))
array([  2.99792458e+08,   1.00000000e+00])


return c / _np.asanyarray(nu)<EOL>

Convert optical frequency to wavelength.

Parameters
----------
nu : array_like
    Optical frequency to be converted.

Returns
-------
lambda : float or array of floats
    Equivalent wavelength(s).

Notes
-----
Computes ``lambda = c / nu`` where c = 299792458.0, i.e., the
(vacuum) speed of light in meters/second.

Examples
--------
>>> from scipy.constants.constants import nu2lambda
>>> nu2lambda(_np.array((1, speed_of_light)))
array([  2.99792458e+08,   1.00000000e+00])


_check_obsolete(key)<EOL>return physical_constants[key][<NUM_LIT:0>]<EOL>

Value in physical_constants indexed by key

Parameters
----------
key : Python string or unicode
    Key in dictionary `physical_constants`

Returns
-------
value : float
    Value in `physical_constants` corresponding to `key`

See Also
--------
codata : Contains the description of `physical_constants`, which, as a
    dictionary literal object, does not itself possess a docstring.

    Examples
--------
>>> from scipy.constants import codata
>>> codata.value('elementary charge')
    1.602176487e-019


_check_obsolete(key)<EOL>return physical_constants[key][<NUM_LIT:1>]<EOL>

Unit in physical_constants indexed by key

Parameters
----------
key : Python string or unicode
    Key in dictionary `physical_constants`

Returns
-------
unit : Python string
    Unit in `physical_constants` corresponding to `key`

See Also
--------
codata : Contains the description of `physical_constants`, which, as a
    dictionary literal object, does not itself possess a docstring.

Examples
--------
>>> from scipy.constants import codata
>>> codata.unit(u'proton mass')
'kg'


_check_obsolete(key)<EOL>return physical_constants[key][<NUM_LIT:2>] / physical_constants[key][<NUM_LIT:0>]<EOL>

Relative precision in physical_constants indexed by key

Parameters
----------
key : Python string or unicode
    Key in dictionary `physical_constants`

Returns
-------
prec : float
    Relative precision in `physical_constants` corresponding to `key`

See Also
--------
codata : Contains the description of `physical_constants`, which, as a
    dictionary literal object, does not itself possess a docstring.

Examples
--------
>>> from scipy.constants import codata
>>> codata.precision(u'proton mass')
4.96226989798e-08


if sub is None:<EOL><INDENT>result = list(_current_constants.keys())<EOL><DEDENT>else:<EOL><INDENT>result = [key for key in _current_constants<EOL>if sub.lower() in key.lower()]<EOL><DEDENT>result.sort()<EOL>if disp:<EOL><INDENT>for key in result:<EOL><INDENT>print(key)<EOL><DEDENT>return<EOL><DEDENT>else:<EOL><INDENT>return result<EOL><DEDENT>

Return list of codata.physical_constant keys containing a given string.

Parameters
----------
sub : str, unicode
    Sub-string to search keys for.  By default, return all keys.
disp : bool
    If True, print the keys that are found, and return None.
    Otherwise, return the list of keys without printing anything.

Returns
-------
keys : list or None
    If `disp` is False, the list of keys is returned.
    Otherwise, None is returned.

See Also
--------
codata : Contains the description of `physical_constants`, which, as a
    dictionary literal object, does not itself possess a docstring.


def ellip_harm(h2, k2, n, p, s, signm=<NUM_LIT:1>, signn=<NUM_LIT:1>):

return _ellip_harm(h2, k2, n, p, s, signm, signn)<EOL>

r"""
    Ellipsoidal harmonic functions E^p_n(l)

    These are also known as Lame functions of the first kind, and are
    solutions to the Lame equation:

    .. math:: (s^2 - h^2)(s^2 - k^2)E''(s) + s(2s^2 - h^2 - k^2)E'(s) + (a - q s^2)E(s) = 0

    where :math:`q = (n+1)n` and :math:`a` is the eigenvalue (not
    returned) corresponding to the solutions.

    Parameters
    ----------
    h2 : float
        ``h**2``
    k2 : float
        ``k**2``; should be larger than ``h**2``
    n : int
        Degree
    s : float
        Coordinate
    p : int
        Order, can range between [1,2n+1]
    signm : {1, -1}, optional
        Sign of prefactor of functions. Can be +/-1. See Notes.
    signn : {1, -1}, optional
        Sign of prefactor of functions. Can be +/-1. See Notes.

    Returns
    -------
    E : float
        the harmonic :math:`E^p_n(s)`

    See Also
    --------
    ellip_harm_2, ellip_normal

    Notes
    -----
    The geometric intepretation of the ellipsoidal functions is
    explained in [2]_, [3]_, [4]_.  The `signm` and `signn` arguments control the
    sign of prefactors for functions according to their type::

        K : +1
        L : signm
        M : signn
        N : signm*signn

    References
    ----------
    .. [1] Digital Libary of Mathematical Functions 29.12
       http://dlmf.nist.gov/29.12
    .. [2] Bardhan and Knepley, "Computational science and
       re-discovery: open-source implementations of
       ellipsoidal harmonics for problems in potential theory",
       Comput. Sci. Disc. 5, 014006 (2012)
       doi:10.1088/1749-4699/5/1/014006
    .. [3] David J.and Dechambre P, "Computation of Ellipsoidal
       Gravity Field Harmonics for small solar system bodies"
       pp. 30-36, 2000
    .. [4] George Dassios, "Ellipsoidal Harmonics: Theory and Applications"
       pp. 418, 2012

    Examples
    --------
    >>> from scipy.special import ellip_harm
    >>> w = ellip_harm(5,8,1,1,2.5)
    >>> w
    2.5

    Check that the functions indeed are solutions to the Lame equation:

    >>> from scipy.interpolate import UnivariateSpline
    >>> def eigenvalue(f, df, ddf):
    ...     r = ((s**2 - h**2)*(s**2 - k**2)*ddf + s*(2*s**2 - h**2 - k**2)*df - n*(n+1)*s**2*f)/f
    ...     return -r.mean(), r.std()
    >>> s = np.linspace(0.1, 10, 200)
    >>> k, h, n, p = 8.0, 2.2, 3, 2
    >>> E = ellip_harm(h**2, k**2, n, p, s)
    >>> E_spl = UnivariateSpline(s, E)
    >>> a, a_err = eigenvalue(E_spl(s), E_spl(s,1), E_spl(s,2))
    >>> a, a_err
    (583.44366156701483, 6.4580890640310646e-11)


with _ellip_lock:<EOL><INDENT>with np.errstate(all='<STR_LIT:ignore>'):<EOL><INDENT>return _ellip_harm_2_vec(h2, k2, n, p, s)<EOL><DEDENT><DEDENT>

r"""
    Ellipsoidal harmonic functions F^p_n(l)

    These are also known as Lame functions of the second kind, and are
    solutions to the Lame equation:

    .. math:: (s^2 - h^2)(s^2 - k^2)F''(s) + s(2s^2 - h^2 - k^2)F'(s) + (a - q s^2)F(s) = 0

    where :math:`q = (n+1)n` and :math:`a` is the eigenvalue (not
    returned) corresponding to the solutions.

    Parameters
    ----------
    h2 : float
        ``h**2``
    k2 : float
        ``k**2``; should be larger than ``h**2``
    n : int
        Degree.
    p : int
        Order, can range between [1,2n+1].
    s : float
        Coordinate

    Returns
    -------
    F : float
        The harmonic :math:`F^p_n(s)`

    Notes
    -----
    Lame functions of the second kind are related to the functions of the first kind:

    .. math::

       F^p_n(s)=(2n + 1)E^p_n(s)\int_{0}^{1/s}\frac{du}{(E^p_n(1/u))^2\sqrt{(1-u^2k^2)(1-u^2h^2)}}

    See Also
    --------
    ellip_harm, ellip_normal

    Examples
    --------
    >>> from scipy.special import ellip_harm_2
    >>> w = ellip_harm_2(5,8,2,1,10)
    >>> w
    0.00108056853382


with _ellip_lock:<EOL><INDENT>with np.errstate(all='<STR_LIT:ignore>'):<EOL><INDENT>return _ellip_normal_vec(h2, k2, n, p)<EOL><DEDENT><DEDENT>

r"""
    Ellipsoidal harmonic normalization constants gamma^p_n

    The normalization constant is defined as

    .. math::

       \gamma^p_n=8\int_{0}^{h}dx\int_{h}^{k}dy\frac{(y^2-x^2)(E^p_n(y)E^p_n(x))^2}{\sqrt((k^2-y^2)(y^2-h^2)(h^2-x^2)(k^2-x^2)}

    Parameters
    ----------
    h2 : float
        ``h**2``
    k2 : float
        ``k**2``; should be larger than ``h**2``
    n: int
        Degree.
    p: int
        Order, can range between [1,2n+1].

    Returns
    -------
    gamma : float
        The normalization constant :math:`\gamma^p_n`

    See Also
    --------
    ellip_harm, ellip_harm_2

    Examples
    --------
    >>> from scipy.special import ellip_normal
    >>> w = ellip_normal(5,8,3,7)
    >>> w
    1723.38796997


def wrapper(*a, **kw):<EOL><INDENT>old_filters = list(getattr(warnings, '<STR_LIT>', []))<EOL>old_errprint = sc.errprint(<NUM_LIT:1>)<EOL>warnings.filterwarnings("<STR_LIT:error>", category=sc.SpecialFunctionWarning)<EOL>try:<EOL><INDENT>return func(*a, **kw)<EOL><DEDENT>finally:<EOL><INDENT>sc.errprint(old_errprint)<EOL>setattr(warnings, '<STR_LIT>', old_filters)<EOL><DEDENT><DEDENT>wrapper.__name__ = func.__name__<EOL>wrapper.__doc__ = func.__doc__<EOL>return wrapper<EOL>

Enable special function errors (such as underflow, overflow,
loss of precision, etc.)


def assert_tol_equal(a, b, rtol=<NUM_LIT>, atol=<NUM_LIT:0>, err_msg='<STR_LIT>', verbose=True):

def compare(x, y):<EOL><INDENT>return np.allclose(x, y, rtol=rtol, atol=atol)<EOL><DEDENT>a, b = np.asanyarray(a), np.asanyarray(b)<EOL>header = '<STR_LIT>' % (rtol, atol)<EOL>np.testing.utils.assert_array_compare(compare, a, b, err_msg=str(err_msg),<EOL>verbose=verbose, header=header)<EOL>

Assert that `a` and `b` are equal to tolerance ``atol + rtol*abs(b)``


if self.knownfailure:<EOL><INDENT>raise KnownFailureTest(self.knownfailure)<EOL><DEDENT>if data is None:<EOL><INDENT>data = self.data<EOL><DEDENT>if dtype is None:<EOL><INDENT>dtype = data.dtype<EOL><DEDENT>else:<EOL><INDENT>data = data.astype(dtype)<EOL><DEDENT>rtol, atol = self.get_tolerances(dtype)<EOL>if self.param_filter:<EOL><INDENT>param_mask = np.ones((data.shape[<NUM_LIT:0>],), np.bool_)<EOL>for j, filter in zip(self.param_columns, self.param_filter):<EOL><INDENT>if filter:<EOL><INDENT>param_mask &= list(filter(data[:,j]))<EOL><DEDENT><DEDENT>data = data[param_mask]<EOL><DEDENT>params = []<EOL>for j in self.param_columns:<EOL><INDENT>if np.iscomplexobj(j):<EOL><INDENT>j = int(j.imag)<EOL>params.append(data[:,j].astype(np.complex))<EOL><DEDENT>else:<EOL><INDENT>params.append(data[:,j])<EOL><DEDENT><DEDENT>def eval_func_at_params(func, skip_mask=None):<EOL><INDENT>if self.vectorized:<EOL><INDENT>got = func(*params)<EOL><DEDENT>else:<EOL><INDENT>got = []<EOL>for j in range(len(params[<NUM_LIT:0>])):<EOL><INDENT>if skip_mask is not None and skip_mask[j]:<EOL><INDENT>got.append(np.nan)<EOL>continue<EOL><DEDENT>got.append(func(*tuple([params[i][j] for i in range(len(params))])))<EOL><DEDENT>got = np.asarray(got)<EOL><DEDENT>if not isinstance(got, tuple):<EOL><INDENT>got = (got,)<EOL><DEDENT>return got<EOL><DEDENT>got = eval_func_at_params(self.func)<EOL>if self.result_columns is not None:<EOL><INDENT>wanted = tuple([data[:,icol] for icol in self.result_columns])<EOL><DEDENT>else:<EOL><INDENT>skip_mask = None<EOL>if self.nan_ok and len(got) == <NUM_LIT:1>:<EOL><INDENT>skip_mask = np.isnan(got[<NUM_LIT:0>])<EOL><DEDENT>wanted = eval_func_at_params(self.result_func, skip_mask=skip_mask)<EOL><DEDENT>assert_(len(got) == len(wanted))<EOL>for output_num, (x, y) in enumerate(zip(got, wanted)):<EOL><INDENT>if np.issubdtype(x.dtype, np.complexfloating) or self.ignore_inf_sign:<EOL><INDENT>pinf_x = np.isinf(x)<EOL>pinf_y = np.isinf(y)<EOL>minf_x = np.isinf(x)<EOL>minf_y = np.isinf(y)<EOL><DEDENT>else:<EOL><INDENT>pinf_x = np.isposinf(x)<EOL>pinf_y = np.isposinf(y)<EOL>minf_x = np.isneginf(x)<EOL>minf_y = np.isneginf(y)<EOL><DEDENT>nan_x = np.isnan(x)<EOL>nan_y = np.isnan(y)<EOL>olderr = np.seterr(all='<STR_LIT:ignore>')<EOL>try:<EOL><INDENT>abs_y = np.absolute(y)<EOL>abs_y[~np.isfinite(abs_y)] = <NUM_LIT:0><EOL>diff = np.absolute(x - y)<EOL>diff[~np.isfinite(diff)] = <NUM_LIT:0><EOL>rdiff = diff / np.absolute(y)<EOL>rdiff[~np.isfinite(rdiff)] = <NUM_LIT:0><EOL><DEDENT>finally:<EOL><INDENT>np.seterr(**olderr)<EOL><DEDENT>tol_mask = (diff <= atol + rtol*abs_y)<EOL>pinf_mask = (pinf_x == pinf_y)<EOL>minf_mask = (minf_x == minf_y)<EOL>nan_mask = (nan_x == nan_y)<EOL>bad_j = ~(tol_mask & pinf_mask & minf_mask & nan_mask)<EOL>point_count = bad_j.size<EOL>if self.nan_ok:<EOL><INDENT>bad_j &= ~nan_x<EOL>bad_j &= ~nan_y<EOL>point_count -= (nan_x | nan_y).sum()<EOL><DEDENT>if np.any(bad_j):<EOL><INDENT>msg = ["<STR_LIT>"]<EOL>msg.append("<STR_LIT>" % diff.max())<EOL>msg.append("<STR_LIT>" % rdiff.max())<EOL>msg.append("<STR_LIT>"<EOL>% (np.sum(bad_j), point_count, output_num,))<EOL>for j in np.where(bad_j)[<NUM_LIT:0>]:<EOL><INDENT>j = int(j)<EOL>fmt = lambda x: "<STR_LIT>" % np.array2string(x[j], precision=<NUM_LIT>)<EOL>a = "<STR_LIT:U+0020>".join(map(fmt, params))<EOL>b = "<STR_LIT:U+0020>".join(map(fmt, got))<EOL>c = "<STR_LIT:U+0020>".join(map(fmt, wanted))<EOL>d = fmt(rdiff)<EOL>msg.append("<STR_LIT>" % (a, b, c, d))<EOL><DEDENT>assert_(False, "<STR_LIT:\n>".join(msg))<EOL><DEDENT><DEDENT>

Check the special function against the data.


if np.any(list(map(np.iscomplexobj, self.param_columns))):<EOL><INDENT>is_complex = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>is_complex = "<STR_LIT>"<EOL><DEDENT>if self.dataname:<EOL><INDENT>return "<STR_LIT>" % (self.func.__name__, is_complex,<EOL>os.path.basename(self.dataname))<EOL><DEDENT>else:<EOL><INDENT>return "<STR_LIT>" % (self.func.__name__, is_complex)<EOL><DEDENT>


def _time_limited(timeout=<NUM_LIT:0.5>, return_val=np.nan, use_sigalrm=True):

if POSIX and use_sigalrm:<EOL><INDENT>def sigalrm_handler(signum, frame):<EOL><INDENT>raise _TimeoutError()<EOL><DEDENT>def deco(func):<EOL><INDENT>def wrap(*a, **kw):<EOL><INDENT>old_handler = signal.signal(signal.SIGALRM, sigalrm_handler)<EOL>signal.setitimer(signal.ITIMER_REAL, timeout)<EOL>try:<EOL><INDENT>return func(*a, **kw)<EOL><DEDENT>except _TimeoutError:<EOL><INDENT>return return_val<EOL><DEDENT>finally:<EOL><INDENT>signal.setitimer(signal.ITIMER_REAL, <NUM_LIT:0>)<EOL>signal.signal(signal.SIGALRM, old_handler)<EOL><DEDENT><DEDENT>return wrap<EOL><DEDENT><DEDENT>else:<EOL><INDENT>def deco(func):<EOL><INDENT>def wrap(*a, **kw):<EOL><INDENT>start_time = time.time()<EOL>def trace(frame, event, arg):<EOL><INDENT>if time.time() - start_time > timeout:<EOL><INDENT>raise _TimeoutError()<EOL><DEDENT>return None  <EOL><DEDENT>sys.settrace(trace)<EOL>try:<EOL><INDENT>return func(*a, **kw)<EOL><DEDENT>except _TimeoutError:<EOL><INDENT>sys.settrace(None)<EOL>return return_val<EOL><DEDENT>finally:<EOL><INDENT>sys.settrace(None)<EOL><DEDENT><DEDENT>return wrap<EOL><DEDENT><DEDENT>return deco<EOL>

Decorator for setting a timeout for pure-Python functions.

If the function does not return within `timeout` seconds, the
value `return_val` is returned instead.

On POSIX this uses SIGALRM by default. On non-POSIX, settrace is
used. Do not use this with threads: the SIGALRM implementation
does probably not work well. The settrace implementation only
traces the current thread.

The settrace implementation slows down execution speed. Slowdown
by a factor around 10 is probably typical.


def wrap(*a, **kw):<EOL><INDENT>try:<EOL><INDENT>return func(*a, **kw)<EOL><DEDENT>except Exception:<EOL><INDENT>return np.nan<EOL><DEDENT><DEDENT>return wrap<EOL>

Decorate function to return nan if it raises an exception


def wrap(*a, **kw):<EOL><INDENT>v = func(*a, **kw)<EOL>if not np.isfinite(v):<EOL><INDENT>return np.nan<EOL><DEDENT>return v<EOL><DEDENT>return wrap<EOL>

Decorate function to return nan if it returns inf


n1 = max(<NUM_LIT:2>, int(<NUM_LIT>*n))<EOL>n2 = max(<NUM_LIT:2>, int(<NUM_LIT>*n))<EOL>n3 = max(<NUM_LIT:8>, n - n1 - n2)<EOL>v1 = np.linspace(-<NUM_LIT:1>, <NUM_LIT:1>, n1)<EOL>v2 = np.r_[np.linspace(-<NUM_LIT:10>, <NUM_LIT:10>, max(<NUM_LIT:0>, n2-<NUM_LIT:4>)),<EOL>-<NUM_LIT:9>, -<NUM_LIT>, <NUM_LIT>, <NUM_LIT:9>]<EOL>if self.a >= <NUM_LIT:0> and self.b > <NUM_LIT:0>:<EOL><INDENT>v3 = np.r_[<EOL>np.logspace(-<NUM_LIT:30>, -<NUM_LIT:1>, <NUM_LIT:2> + n3//<NUM_LIT:4>),<EOL>np.logspace(<NUM_LIT:5>, np.log10(self.b), <NUM_LIT:1> + n3//<NUM_LIT:4>),<EOL>]<EOL>v4 = np.logspace(<NUM_LIT:1>, <NUM_LIT:5>, <NUM_LIT:1> + n3//<NUM_LIT:2>)<EOL><DEDENT>elif self.a < <NUM_LIT:0> and self.b > <NUM_LIT:0>:<EOL><INDENT>v3 = np.r_[<EOL>np.logspace(-<NUM_LIT:30>, -<NUM_LIT:1>, <NUM_LIT:2> + n3//<NUM_LIT:8>),<EOL>np.logspace(<NUM_LIT:5>, np.log10(self.b), <NUM_LIT:1> + n3//<NUM_LIT:8>),<EOL>-np.logspace(-<NUM_LIT:30>, -<NUM_LIT:1>, <NUM_LIT:2> + n3//<NUM_LIT:8>),<EOL>-np.logspace(<NUM_LIT:5>, np.log10(-self.a), <NUM_LIT:1> + n3//<NUM_LIT:8>)<EOL>]<EOL>v4 = np.r_[<EOL>np.logspace(<NUM_LIT:1>, <NUM_LIT:5>, <NUM_LIT:1> + n3//<NUM_LIT:4>),<EOL>-np.logspace(<NUM_LIT:1>, <NUM_LIT:5>, <NUM_LIT:1> + n3//<NUM_LIT:4>)<EOL>]<EOL><DEDENT>elif self.b < <NUM_LIT:0>:<EOL><INDENT>v3 = np.r_[<EOL>-np.logspace(-<NUM_LIT:30>, -<NUM_LIT:1>, <NUM_LIT:2> + n3//<NUM_LIT:4>),<EOL>-np.logspace(<NUM_LIT:5>, np.log10(-self.b), <NUM_LIT:1> + n3//<NUM_LIT:4>),<EOL>]<EOL>v4 = -np.logspace(<NUM_LIT:1>, <NUM_LIT:5>, <NUM_LIT:1> + n3//<NUM_LIT:2>)<EOL><DEDENT>else:<EOL><INDENT>v3 = []<EOL>v4 = []<EOL><DEDENT>v = np.r_[v1, v2, v3, v4, <NUM_LIT:0>]<EOL>if self.inclusive_a:<EOL><INDENT>v = v[v >= self.a]<EOL><DEDENT>else:<EOL><INDENT>v = v[v > self.a]<EOL><DEDENT>if self.inclusive_b:<EOL><INDENT>v = v[v <= self.b]<EOL><DEDENT>else:<EOL><INDENT>v = v[v < self.b]<EOL><DEDENT>return np.unique(v)<EOL>

Return an array containing approximatively `n` numbers.


<EOL>for v in [-<NUM_LIT>, -<NUM_LIT>, -<NUM_LIT>, -<NUM_LIT>, -<NUM_LIT:1.>, -<NUM_LIT>,<EOL><NUM_LIT:0.>, <NUM_LIT:1.>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>]:<EOL><INDENT>for z in [-<NUM_LIT>, -<NUM_LIT:11>, -<NUM_LIT:10>, -<NUM_LIT:1>, <NUM_LIT:1.>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>,<EOL><NUM_LIT>, <NUM_LIT>, <NUM_LIT>]:<EOL><INDENT>yield v, z<EOL><DEDENT><DEDENT>for v in <NUM_LIT:0.5> + arange(-<NUM_LIT>, <NUM_LIT>):<EOL><INDENT>yield v, <NUM_LIT><EOL><DEDENT>

Yield points at which to compare Cephes implementation to AMOS


def _series(self, v, z, n=<NUM_LIT:100>):

k = arange(<NUM_LIT:0>, n)<EOL>r = (-<NUM_LIT:1>)**k * (<NUM_LIT>*z)**(<NUM_LIT:2>*k+v+<NUM_LIT:1>)/special.gamma(k+<NUM_LIT>)/special.gamma(k+v+<NUM_LIT>)<EOL>err = abs(r).max() * finfo(float_).eps * n<EOL>return r.sum(), err<EOL>

Compute Struve function & error estimate from its power series.


x,n = asarray(x), asarray(n)<EOL>n = asarray(n + (x-x))<EOL>x = asarray(x + (n-n))<EOL>if issubdtype(x.dtype, inexact):<EOL><INDENT>ytype = x.dtype<EOL><DEDENT>else:<EOL><INDENT>ytype = float<EOL><DEDENT>y = zeros(x.shape,ytype)<EOL>mask1 = (n <= <NUM_LIT:0>) | (n != floor(n))<EOL>place(y,mask1,nan)<EOL>z = asarray(x / <NUM_LIT> / pi)<EOL>mask2 = (<NUM_LIT:1>-mask1) & (z == floor(z))<EOL>zsub = extract(mask2,z)<EOL>nsub = extract(mask2,n)<EOL>place(y,mask2,pow(-<NUM_LIT:1>,zsub*(nsub-<NUM_LIT:1>)))<EOL>mask = (<NUM_LIT:1>-mask1) & (<NUM_LIT:1>-mask2)<EOL>xsub = extract(mask,x)<EOL>nsub = extract(mask,n)<EOL>place(y,mask,sin(nsub*xsub/<NUM_LIT>)/(nsub*sin(xsub/<NUM_LIT>)))<EOL>return y<EOL>

Returns the periodic sinc function, also called the Dirichlet function

    The Dirichlet function is defined as::

        diric(x) = sin(x * n/2) / (n * sin(x / 2)),

    where n is a positive integer.

    Parameters
    ----------
    x : array_like
        Input data
    n : int
        Integer defining the periodicity.

    Returns
    -------
    diric : ndarray


if not isscalar(nt) or (floor(nt) != nt) or (nt > <NUM_LIT>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>nt = int(nt)<EOL>n,m,t,zo = specfun.jdzo(nt)<EOL>return zo[<NUM_LIT:1>:nt+<NUM_LIT:1>],n[:nt],m[:nt],t[:nt]<EOL>

Compute nt (<=1200) zeros of the Bessel functions Jn and Jn'
    and arange them in order of their magnitudes.

    Returns
    -------
    zo[l-1] : ndarray
        Value of the lth zero of Jn(x) and Jn'(x). Of length `nt`.
    n[l-1] : ndarray
        Order of the Jn(x) or Jn'(x) associated with lth zero. Of length `nt`.
    m[l-1] : ndarray
        Serial number of the zeros of Jn(x) or Jn'(x) associated
        with lth zero. Of length `nt`.
    t[l-1] : ndarray
        0 if lth zero in zo is zero of Jn(x), 1 if it is a zero of Jn'(x). Of
        length `nt`.

    See Also
    --------
    jn_zeros, jnp_zeros : to get separated arrays of zeros.


if not (isscalar(nt) and isscalar(n)):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (floor(n) != n) or (floor(nt) != nt):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (nt <= <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return specfun.jyzo(abs(n),nt)<EOL>

Compute nt zeros of the Bessel functions Jn(x), Jn'(x), Yn(x), and
    Yn'(x), respectively. Returns 4 arrays of length nt.

    See jn_zeros, jnp_zeros, yn_zeros, ynp_zeros to get separate arrays.


return jnyn_zeros(n,nt)[<NUM_LIT:0>]<EOL>

Compute nt zeros of the Bessel function Jn(x).


return jnyn_zeros(n,nt)[<NUM_LIT:1>]<EOL>

Compute nt zeros of the Bessel function Jn'(x).


return jnyn_zeros(n,nt)[<NUM_LIT:2>]<EOL>

Compute nt zeros of the Bessel function Yn(x).


return jnyn_zeros(n,nt)[<NUM_LIT:3>]<EOL>

Compute nt zeros of the Bessel function Yn'(x).


if not isscalar(nt) or (floor(nt) != nt) or (nt <= <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>kf = <NUM_LIT:0><EOL>kc = (complex != <NUM_LIT:1>)<EOL>return specfun.cyzo(nt,kf,kc)<EOL>

Returns nt (complex or real) zeros of Y0(z), z0, and the value
    of Y0'(z0) = -Y1(z0) at each zero.


if not isscalar(nt) or (floor(nt) != nt) or (nt <= <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>kf = <NUM_LIT:1><EOL>kc = (complex != <NUM_LIT:1>)<EOL>return specfun.cyzo(nt,kf,kc)<EOL>

Returns nt (complex or real) zeros of Y1(z), z1, and the value
    of Y1'(z1) = Y0(z1) at each zero.


if not isscalar(nt) or (floor(nt) != nt) or (nt <= <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>kf = <NUM_LIT:2><EOL>kc = (complex != <NUM_LIT:1>)<EOL>return specfun.cyzo(nt,kf,kc)<EOL>

Returns nt (complex or real) zeros of Y1'(z), z1', and the value
    of Y1(z1') at each zero.


if not isinstance(n,int) or (n < <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if n == <NUM_LIT:0>:<EOL><INDENT>return jv(v,z)<EOL><DEDENT>else:<EOL><INDENT>return _bessel_diff_formula(v, z, n, jv, -<NUM_LIT:1>)<EOL><DEDENT>

Return the nth derivative of Jv(z) with respect to z.


if not isinstance(n,int) or (n < <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if n == <NUM_LIT:0>:<EOL><INDENT>return yv(v,z)<EOL><DEDENT>else:<EOL><INDENT>return _bessel_diff_formula(v, z, n, yv, -<NUM_LIT:1>)<EOL><DEDENT>

Return the nth derivative of Yv(z) with respect to z.


if not isinstance(n,int) or (n < <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if n == <NUM_LIT:0>:<EOL><INDENT>return kv(v,z)<EOL><DEDENT>else:<EOL><INDENT>return (-<NUM_LIT:1>)**n * _bessel_diff_formula(v, z, n, kv, <NUM_LIT:1>)<EOL><DEDENT>

Return the nth derivative of Kv(z) with respect to z.


if not isinstance(n,int) or (n < <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if n == <NUM_LIT:0>:<EOL><INDENT>return iv(v,z)<EOL><DEDENT>else:<EOL><INDENT>return _bessel_diff_formula(v, z, n, iv, <NUM_LIT:1>)<EOL><DEDENT>

Return the nth derivative of Iv(z) with respect to z.


if not isinstance(n,int) or (n < <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if n == <NUM_LIT:0>:<EOL><INDENT>return hankel1(v,z)<EOL><DEDENT>else:<EOL><INDENT>return _bessel_diff_formula(v, z, n, hankel1, -<NUM_LIT:1>)<EOL><DEDENT>

Return the nth derivative of H1v(z) with respect to z.


if not isinstance(n,int) or (n < <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if n == <NUM_LIT:0>:<EOL><INDENT>return hankel2(v,z)<EOL><DEDENT>else:<EOL><INDENT>return _bessel_diff_formula(v, z, n, hankel2, -<NUM_LIT:1>)<EOL><DEDENT>

Return the nth derivative of H2v(z) with respect to z.


if not (isscalar(n) and isscalar(z)):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (n != floor(n)) or (n < <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (n < <NUM_LIT:1>):<EOL><INDENT>n1 = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>n1 = n<EOL><DEDENT>if iscomplex(z):<EOL><INDENT>nm,jn,jnp,yn,ynp = specfun.csphjy(n1,z)<EOL><DEDENT>else:<EOL><INDENT>nm,jn,jnp = specfun.sphj(n1,z)<EOL><DEDENT>return jn[:(n+<NUM_LIT:1>)], jnp[:(n+<NUM_LIT:1>)]<EOL>

Compute the spherical Bessel function jn(z) and its derivative for
    all orders up to and including n.


if not (isscalar(n) and isscalar(z)):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (n != floor(n)) or (n < <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (n < <NUM_LIT:1>):<EOL><INDENT>n1 = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>n1 = n<EOL><DEDENT>if iscomplex(z) or less(z,<NUM_LIT:0>):<EOL><INDENT>nm,jn,jnp,yn,ynp = specfun.csphjy(n1,z)<EOL><DEDENT>else:<EOL><INDENT>nm,yn,ynp = specfun.sphy(n1,z)<EOL><DEDENT>return yn[:(n+<NUM_LIT:1>)], ynp[:(n+<NUM_LIT:1>)]<EOL>

Compute the spherical Bessel function yn(z) and its derivative for
    all orders up to and including n.


if not (isscalar(n) and isscalar(z)):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (n != floor(n)) or (n < <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (n < <NUM_LIT:1>):<EOL><INDENT>n1 = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>n1 = n<EOL><DEDENT>if iscomplex(z) or less(z,<NUM_LIT:0>):<EOL><INDENT>nm,jn,jnp,yn,ynp = specfun.csphjy(n1,z)<EOL><DEDENT>else:<EOL><INDENT>nm,yn,ynp = specfun.sphy(n1,z)<EOL>nm,jn,jnp = specfun.sphj(n1,z)<EOL><DEDENT>return jn[:(n+<NUM_LIT:1>)],jnp[:(n+<NUM_LIT:1>)],yn[:(n+<NUM_LIT:1>)],ynp[:(n+<NUM_LIT:1>)]<EOL>

Compute the spherical Bessel functions, jn(z) and yn(z) and their
    derivatives for all orders up to and including n.


if not (isscalar(n) and isscalar(z)):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (n != floor(n)) or (n < <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (n < <NUM_LIT:1>):<EOL><INDENT>n1 = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>n1 = n<EOL><DEDENT>if iscomplex(z):<EOL><INDENT>nm,In,Inp,kn,knp = specfun.csphik(n1,z)<EOL><DEDENT>else:<EOL><INDENT>nm,In,Inp = specfun.sphi(n1,z)<EOL><DEDENT>return In[:(n+<NUM_LIT:1>)], Inp[:(n+<NUM_LIT:1>)]<EOL>

Compute the spherical Bessel function in(z) and its derivative for
    all orders up to and including n.


if not (isscalar(n) and isscalar(z)):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (n != floor(n)) or (n < <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (n < <NUM_LIT:1>):<EOL><INDENT>n1 = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>n1 = n<EOL><DEDENT>if iscomplex(z) or less(z,<NUM_LIT:0>):<EOL><INDENT>nm,In,Inp,kn,knp = specfun.csphik(n1,z)<EOL><DEDENT>else:<EOL><INDENT>nm,kn,knp = specfun.sphk(n1,z)<EOL><DEDENT>return kn[:(n+<NUM_LIT:1>)], knp[:(n+<NUM_LIT:1>)]<EOL>

Compute the spherical Bessel function kn(z) and its derivative for
    all orders up to and including n.


if not (isscalar(n) and isscalar(z)):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (n != floor(n)) or (n < <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (n < <NUM_LIT:1>):<EOL><INDENT>n1 = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>n1 = n<EOL><DEDENT>if iscomplex(z) or less(z,<NUM_LIT:0>):<EOL><INDENT>nm,In,Inp,kn,knp = specfun.csphik(n1,z)<EOL><DEDENT>else:<EOL><INDENT>nm,In,Inp = specfun.sphi(n1,z)<EOL>nm,kn,knp = specfun.sphk(n1,z)<EOL><DEDENT>return In[:(n+<NUM_LIT:1>)],Inp[:(n+<NUM_LIT:1>)],kn[:(n+<NUM_LIT:1>)],knp[:(n+<NUM_LIT:1>)]<EOL>

Compute the spherical Bessel functions, in(z) and kn(z) and their
    derivatives for all orders up to and including n.


if not (isscalar(n) and isscalar(x)):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (n != floor(n)) or (n < <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (n == <NUM_LIT:0>):<EOL><INDENT>n1 = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>n1 = n<EOL><DEDENT>nm,jn,jnp = specfun.rctj(n1,x)<EOL>return jn[:(n+<NUM_LIT:1>)],jnp[:(n+<NUM_LIT:1>)]<EOL>

Compute the Ricatti-Bessel function of the first kind and its
    derivative for all orders up to and including n.


if not (isscalar(n) and isscalar(x)):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (n != floor(n)) or (n < <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (n == <NUM_LIT:0>):<EOL><INDENT>n1 = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>n1 = n<EOL><DEDENT>nm,jn,jnp = specfun.rcty(n1,x)<EOL>return jn[:(n+<NUM_LIT:1>)],jnp[:(n+<NUM_LIT:1>)]<EOL>

Compute the Ricatti-Bessel function of the second kind and its
    derivative for all orders up to and including n.


return ndtri((y+<NUM_LIT:1>)/<NUM_LIT>)/sqrt(<NUM_LIT:2>)<EOL>


return -ndtri(<NUM_LIT:0.5>*y)/sqrt(<NUM_LIT:2>)<EOL>


if (floor(nt) != nt) or (nt <= <NUM_LIT:0>) or not isscalar(nt):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return specfun.cerzo(nt)<EOL>

Compute nt complex zeros of the error function erf(z).


if (floor(nt) != nt) or (nt <= <NUM_LIT:0>) or not isscalar(nt):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return specfun.fcszo(<NUM_LIT:1>,nt)<EOL>

Compute nt complex zeros of the cosine Fresnel integral C(z).


if (floor(nt) != nt) or (nt <= <NUM_LIT:0>) or not isscalar(nt):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return specfun.fcszo(<NUM_LIT:2>,nt)<EOL>

Compute nt complex zeros of the sine Fresnel integral S(z).


if (floor(nt) != nt) or (nt <= <NUM_LIT:0>) or not isscalar(nt):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return specfun.fcszo(<NUM_LIT:2>,nt), specfun.fcszo(<NUM_LIT:1>,nt)<EOL>

Compute nt complex zeros of the sine and cosine Fresnel integrals
    S(z) and C(z).


v = atleast_1d(v)<EOL>z = atleast_1d(z)<EOL>v, z = np.broadcast_arrays(v, z)<EOL>arg = <NUM_LIT:2> * sqrt(abs(z))<EOL>old_err = np.seterr(all='<STR_LIT:ignore>')  <EOL>num = where(z.real >= <NUM_LIT:0>, iv(v - <NUM_LIT:1>, arg), jv(v - <NUM_LIT:1>, arg))<EOL>den = abs(z)**((v - <NUM_LIT:1.0>) / <NUM_LIT:2>)<EOL>num *= gamma(v)<EOL>np.seterr(**old_err)<EOL>num[z == <NUM_LIT:0>] = <NUM_LIT:1><EOL>den[z == <NUM_LIT:0>] = <NUM_LIT:1><EOL>return num / den<EOL>

r"""Confluent hypergeometric limit function 0F1.

    Parameters
    ----------
    v, z : array_like
        Input values.

    Returns
    -------
    hyp0f1 : ndarray
        The confluent hypergeometric limit function.

    Notes
    -----
    This function is defined as:

    .. math:: _0F_1(v,z) = \sum_{k=0}^{\inf}\frac{z^k}{(v)_k k!}.

    It's also the limit as q -> infinity of ``1F1(q;v;z/q)``, and satisfies
    the differential equation :math:``f''(z) + vf'(z) = f(z)`.


def assoc_laguerre(x, n, k=<NUM_LIT:0.0>):

return orthogonal.eval_genlaguerre(n, k, x)<EOL>

Returns the n-th order generalized (associated) Laguerre polynomial.

    The polynomial :math:`L^(alpha)_n(x)` is orthogonal over ``[0, inf)``,
    with weighting function ``exp(-x) * x**alpha`` with ``alpha > -1``.

    Notes
    -----
    `assoc_laguerre` is a simple wrapper around `eval_genlaguerre`, with
    reversed argument order ``(x, n, k=0.0) --> (n, k, x)``.


n, x = asarray(n), asarray(x)<EOL>fac2 = (-<NUM_LIT:1.0>)**(n+<NUM_LIT:1>) * gamma(n+<NUM_LIT:1.0>) * zeta(n+<NUM_LIT:1>,x)<EOL>return where(n == <NUM_LIT:0>, psi(x), fac2)<EOL>

Polygamma function which is the nth derivative of the digamma (psi)
    function.

    Parameters
    ----------
    n : array_like of int
        The order of the derivative of `psi`.
    x : array_like
        Where to evaluate the polygamma function.

    Returns
    -------
    polygamma : ndarray
        The result.

    Examples
    --------
    >>> from scipy import special
    >>> x = [2, 3, 25.5]
    >>> special.polygamma(1, x)
    array([ 0.64493407,  0.39493407,  0.03999467])
    >>> special.polygamma(0, x) == special.psi(x)
    array([ True,  True,  True], dtype=bool)


if not (isscalar(m) and isscalar(q)):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (q < <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (m != floor(m)) or (m < <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (q <= <NUM_LIT:1>):<EOL><INDENT>qm = <NUM_LIT>+<NUM_LIT>*sqrt(q)-<NUM_LIT>*q+<NUM_LIT>*sqrt(q)*q<EOL><DEDENT>else:<EOL><INDENT>qm = <NUM_LIT>+<NUM_LIT>*sqrt(q)-<NUM_LIT>*q+<NUM_LIT>*sqrt(q)*q<EOL><DEDENT>km = int(qm+<NUM_LIT:0.5>*m)<EOL>if km > <NUM_LIT>:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>kd = <NUM_LIT:1><EOL>m = int(floor(m))<EOL>if m % <NUM_LIT:2>:<EOL><INDENT>kd = <NUM_LIT:2><EOL><DEDENT>a = mathieu_a(m,q)<EOL>fc = specfun.fcoef(kd,m,q,a)<EOL>return fc[:km]<EOL>

Compute expansion coefficients for even Mathieu functions and
    modified Mathieu functions.


if not (isscalar(m) and isscalar(q)):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (q < <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (m != floor(m)) or (m <= <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (q <= <NUM_LIT:1>):<EOL><INDENT>qm = <NUM_LIT>+<NUM_LIT>*sqrt(q)-<NUM_LIT>*q+<NUM_LIT>*sqrt(q)*q<EOL><DEDENT>else:<EOL><INDENT>qm = <NUM_LIT>+<NUM_LIT>*sqrt(q)-<NUM_LIT>*q+<NUM_LIT>*sqrt(q)*q<EOL><DEDENT>km = int(qm+<NUM_LIT:0.5>*m)<EOL>if km > <NUM_LIT>:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>kd = <NUM_LIT:4><EOL>m = int(floor(m))<EOL>if m % <NUM_LIT:2>:<EOL><INDENT>kd = <NUM_LIT:3><EOL><DEDENT>b = mathieu_b(m,q)<EOL>fc = specfun.fcoef(kd,m,q,b)<EOL>return fc[:km]<EOL>


if not isscalar(m) or (abs(m) > n):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not isscalar(n) or (n < <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not isscalar(z):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if iscomplex(z):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (m < <NUM_LIT:0>):<EOL><INDENT>mp = -m<EOL>mf,nf = mgrid[<NUM_LIT:0>:mp+<NUM_LIT:1>,<NUM_LIT:0>:n+<NUM_LIT:1>]<EOL>sv = errprint(<NUM_LIT:0>)<EOL>if abs(z) < <NUM_LIT:1>:<EOL><INDENT>fixarr = where(mf > nf,<NUM_LIT:0.0>,(-<NUM_LIT:1>)**mf * gamma(nf-mf+<NUM_LIT:1>) / gamma(nf+mf+<NUM_LIT:1>))<EOL><DEDENT>else:<EOL><INDENT>fixarr = where(mf > nf,<NUM_LIT:0.0>, gamma(nf-mf+<NUM_LIT:1>) / gamma(nf+mf+<NUM_LIT:1>))<EOL><DEDENT>sv = errprint(sv)<EOL><DEDENT>else:<EOL><INDENT>mp = m<EOL><DEDENT>p,pd = specfun.lpmn(mp,n,z)<EOL>if (m < <NUM_LIT:0>):<EOL><INDENT>p = p * fixarr<EOL>pd = pd * fixarr<EOL><DEDENT>return p,pd<EOL>

Associated Legendre function of the first kind, Pmn(z)

    Computes the associated Legendre function of the first kind
    of order m and degree n,::

        Pmn(z) = P_n^m(z)

    and its derivative, ``Pmn'(z)``.  Returns two arrays of size
    ``(m+1, n+1)`` containing ``Pmn(z)`` and ``Pmn'(z)`` for all
    orders from ``0..m`` and degrees from ``0..n``.

    This function takes a real argument ``z``. For complex arguments ``z``
    use clpmn instead.

    Parameters
    ----------
    m : int
       ``|m| <= n``; the order of the Legendre function.
    n : int
       where ``n >= 0``; the degree of the Legendre function.  Often
       called ``l`` (lower case L) in descriptions of the associated
       Legendre function
    z : float
        Input value.

    Returns
    -------
    Pmn_z : (m+1, n+1) array
       Values for all orders 0..m and degrees 0..n
    Pmn_d_z : (m+1, n+1) array
       Derivatives for all orders 0..m and degrees 0..n

    See Also
    --------
    clpmn: associated Legendre functions of the first kind for complex z

    Notes
    -----
    In the interval (-1, 1), Ferrer's function of the first kind is
    returned. The phase convention used for the intervals (1, inf)
    and (-inf, -1) is such that the result is always real.

    References
    ----------
    .. [1] NIST Digital Library of Mathematical Functions
           http://dlmf.nist.gov/14.3


if not isscalar(m) or (abs(m) > n):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not isscalar(n) or (n < <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not isscalar(z):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not(type == <NUM_LIT:2> or type == <NUM_LIT:3>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (m < <NUM_LIT:0>):<EOL><INDENT>mp = -m<EOL>mf,nf = mgrid[<NUM_LIT:0>:mp+<NUM_LIT:1>,<NUM_LIT:0>:n+<NUM_LIT:1>]<EOL>sv = errprint(<NUM_LIT:0>)<EOL>if type == <NUM_LIT:2>:<EOL><INDENT>fixarr = where(mf > nf,<NUM_LIT:0.0>, (-<NUM_LIT:1>)**mf * gamma(nf-mf+<NUM_LIT:1>) / gamma(nf+mf+<NUM_LIT:1>))<EOL><DEDENT>else:<EOL><INDENT>fixarr = where(mf > nf,<NUM_LIT:0.0>,gamma(nf-mf+<NUM_LIT:1>) / gamma(nf+mf+<NUM_LIT:1>))<EOL><DEDENT>sv = errprint(sv)<EOL><DEDENT>else:<EOL><INDENT>mp = m<EOL><DEDENT>p,pd = specfun.clpmn(mp,n,real(z),imag(z),type)<EOL>if (m < <NUM_LIT:0>):<EOL><INDENT>p = p * fixarr<EOL>pd = pd * fixarr<EOL><DEDENT>return p,pd<EOL>

Associated Legendre function of the first kind, Pmn(z)

    Computes the (associated) Legendre function of the first kind
    of order m and degree n,::

        Pmn(z) = P_n^m(z)

    and its derivative, ``Pmn'(z)``.  Returns two arrays of size
    ``(m+1, n+1)`` containing ``Pmn(z)`` and ``Pmn'(z)`` for all
    orders from ``0..m`` and degrees from ``0..n``.

    Parameters
    ----------
    m : int
       ``|m| <= n``; the order of the Legendre function.
    n : int
       where ``n >= 0``; the degree of the Legendre function.  Often
       called ``l`` (lower case L) in descriptions of the associated
       Legendre function
    z : float or complex
        Input value.
    type : int
       takes values 2 or 3
       2: cut on the real axis |x|>1
       3: cut on the real axis -1<x<1 (default)

    Returns
    -------
    Pmn_z : (m+1, n+1) array
       Values for all orders 0..m and degrees 0..n
    Pmn_d_z : (m+1, n+1) array
       Derivatives for all orders 0..m and degrees 0..n

    See Also
    --------
    lpmn: associated Legendre functions of the first kind for real z

    Notes
    -----
    By default, i.e. for ``type=3``, phase conventions are chosen according
    to [1]_ such that the function is analytic. The cut lies on the interval
    (-1, 1). Approaching the cut from above or below in general yields a phase
    factor with respect to Ferrer's function of the first kind
    (cf. `lpmn`).

    For ``type=2`` a cut at |x|>1 is chosen. Approaching the real values
    on the interval (-1, 1) in the complex plane yields Ferrer's function
    of the first kind.

    References
    ----------
    .. [1] NIST Digital Library of Mathematical Functions
           http://dlmf.nist.gov/14.21


if not isscalar(m) or (m < <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not isscalar(n) or (n < <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not isscalar(z):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>m = int(m)<EOL>n = int(n)<EOL>mm = max(<NUM_LIT:1>,m)<EOL>nn = max(<NUM_LIT:1>,n)<EOL>if iscomplex(z):<EOL><INDENT>q,qd = specfun.clqmn(mm,nn,z)<EOL><DEDENT>else:<EOL><INDENT>q,qd = specfun.lqmn(mm,nn,z)<EOL><DEDENT>return q[:(m+<NUM_LIT:1>),:(n+<NUM_LIT:1>)],qd[:(m+<NUM_LIT:1>),:(n+<NUM_LIT:1>)]<EOL>

Associated Legendre functions of the second kind, Qmn(z) and its
    derivative, ``Qmn'(z)`` of order m and degree n.  Returns two
    arrays of size ``(m+1, n+1)`` containing ``Qmn(z)`` and ``Qmn'(z)`` for
    all orders from ``0..m`` and degrees from ``0..n``.

    z can be complex.


if not isscalar(n) or (n < <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>n = int(n)<EOL>if (n < <NUM_LIT:2>):<EOL><INDENT>n1 = <NUM_LIT:2><EOL><DEDENT>else:<EOL><INDENT>n1 = n<EOL><DEDENT>return specfun.bernob(int(n1))[:(n+<NUM_LIT:1>)]<EOL>

Return an array of the Bernoulli numbers B0..Bn


if not isscalar(n) or (n < <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>n = int(n)<EOL>if (n < <NUM_LIT:2>):<EOL><INDENT>n1 = <NUM_LIT:2><EOL><DEDENT>else:<EOL><INDENT>n1 = n<EOL><DEDENT>return specfun.eulerb(n1)[:(n+<NUM_LIT:1>)]<EOL>

Return an array of the Euler numbers E0..En (inclusive)


if not (isscalar(n) and isscalar(z)):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (n != floor(n)) or (n < <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (n < <NUM_LIT:1>):<EOL><INDENT>n1 = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>n1 = n<EOL><DEDENT>if iscomplex(z):<EOL><INDENT>pn,pd = specfun.clpn(n1,z)<EOL><DEDENT>else:<EOL><INDENT>pn,pd = specfun.lpn(n1,z)<EOL><DEDENT>return pn[:(n+<NUM_LIT:1>)],pd[:(n+<NUM_LIT:1>)]<EOL>

Compute sequence of Legendre functions of the first kind (polynomials),
    Pn(z) and derivatives for all degrees from 0 to n (inclusive).

    See also special.legendre  for polynomial class.


if not (isscalar(n) and isscalar(z)):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (n != floor(n)) or (n < <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (n < <NUM_LIT:1>):<EOL><INDENT>n1 = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>n1 = n<EOL><DEDENT>if iscomplex(z):<EOL><INDENT>qn,qd = specfun.clqn(n1,z)<EOL><DEDENT>else:<EOL><INDENT>qn,qd = specfun.lqnb(n1,z)<EOL><DEDENT>return qn[:(n+<NUM_LIT:1>)],qd[:(n+<NUM_LIT:1>)]<EOL>

Compute sequence of Legendre functions of the second kind,
    Qn(z) and derivatives for all degrees from 0 to n (inclusive).


kf = <NUM_LIT:1><EOL>if not isscalar(nt) or (floor(nt) != nt) or (nt <= <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return specfun.airyzo(nt,kf)<EOL>

Compute the zeros of Airy Functions Ai(x) and Ai'(x), a and a'
    respectively, and the associated values of Ai(a') and Ai'(a).

    Returns
    -------
    a[l-1]   -- the lth zero of Ai(x)
    ap[l-1]  -- the lth zero of Ai'(x)
    ai[l-1]  -- Ai(ap[l-1])
    aip[l-1] -- Ai'(a[l-1])


kf = <NUM_LIT:2><EOL>if not isscalar(nt) or (floor(nt) != nt) or (nt <= <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return specfun.airyzo(nt,kf)<EOL>

Compute the zeros of Airy Functions Bi(x) and Bi'(x), b and b'
    respectively, and the associated values of Ai(b') and Ai'(b).

    Returns
    -------
    b[l-1]   -- the lth zero of Bi(x)
    bp[l-1]  -- the lth zero of Bi'(x)
    bi[l-1]  -- Bi(bp[l-1])
    bip[l-1] -- Bi'(b[l-1])


if not (isscalar(v) and isscalar(x)):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (v < <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>n = int(v)<EOL>v0 = v - n<EOL>if (n < <NUM_LIT:1>):<EOL><INDENT>n1 = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>n1 = n<EOL><DEDENT>v1 = n1 + v0<EOL>if (v != floor(v)):<EOL><INDENT>vm, vl, dl = specfun.lamv(v1,x)<EOL><DEDENT>else:<EOL><INDENT>vm, vl, dl = specfun.lamn(v1,x)<EOL><DEDENT>return vl[:(n+<NUM_LIT:1>)], dl[:(n+<NUM_LIT:1>)]<EOL>

Compute sequence of lambda functions with arbitrary order v
    and their derivatives.  Lv0(x)..Lv(x) are computed with v0=v-int(v).


if not (isscalar(v) and isscalar(x)):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>n = int(v)<EOL>v0 = v-n<EOL>if (n < <NUM_LIT:1>):<EOL><INDENT>n1 = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>n1 = n<EOL><DEDENT>v1 = n1 + v0<EOL>dv,dp,pdf,pdd = specfun.pbdv(v1,x)<EOL>return dv[:n1+<NUM_LIT:1>],dp[:n1+<NUM_LIT:1>]<EOL>

Compute sequence of parabolic cylinder functions Dv(x) and
    their derivatives for Dv0(x)..Dv(x) with v0=v-int(v).


if not (isscalar(v) and isscalar(x)):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>n = int(v)<EOL>v0 = v-n<EOL>if (n <= <NUM_LIT:1>):<EOL><INDENT>n1 = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>n1 = n<EOL><DEDENT>v1 = n1 + v0<EOL>dv,dp,pdf,pdd = specfun.pbvv(v1,x)<EOL>return dv[:n1+<NUM_LIT:1>],dp[:n1+<NUM_LIT:1>]<EOL>


if not (isscalar(n) and isscalar(z)):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (floor(n) != n):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (abs(n) <= <NUM_LIT:1>):<EOL><INDENT>n1 = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>n1 = n<EOL><DEDENT>cpb,cpd = specfun.cpbdn(n1,z)<EOL>return cpb[:n1+<NUM_LIT:1>],cpd[:n1+<NUM_LIT:1>]<EOL>

Compute sequence of parabolic cylinder functions Dn(z) and
    their derivatives for D0(z)..Dn(z).


if not isscalar(nt) or (floor(nt) != nt) or (nt <= <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return specfun.klvnzo(nt,<NUM_LIT:1>)<EOL>

Compute nt zeros of the Kelvin function ber x


if not isscalar(nt) or (floor(nt) != nt) or (nt <= <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return specfun.klvnzo(nt,<NUM_LIT:2>)<EOL>

Compute nt zeros of the Kelvin function bei x


if not isscalar(nt) or (floor(nt) != nt) or (nt <= <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return specfun.klvnzo(nt,<NUM_LIT:3>)<EOL>

Compute nt zeros of the Kelvin function ker x


if not isscalar(nt) or (floor(nt) != nt) or (nt <= <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return specfun.klvnzo(nt,<NUM_LIT:4>)<EOL>

Compute nt zeros of the Kelvin function kei x


if not isscalar(nt) or (floor(nt) != nt) or (nt <= <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return specfun.klvnzo(nt,<NUM_LIT:5>)<EOL>

Compute nt zeros of the Kelvin function ber' x


if not isscalar(nt) or (floor(nt) != nt) or (nt <= <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return specfun.klvnzo(nt,<NUM_LIT:6>)<EOL>

Compute nt zeros of the Kelvin function bei' x


if not isscalar(nt) or (floor(nt) != nt) or (nt <= <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return specfun.klvnzo(nt,<NUM_LIT:7>)<EOL>

Compute nt zeros of the Kelvin function ker' x


if not isscalar(nt) or (floor(nt) != nt) or (nt <= <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return specfun.klvnzo(nt,<NUM_LIT:8>)<EOL>

Compute nt zeros of the Kelvin function kei' x


if not isscalar(nt) or (floor(nt) != nt) or (nt <= <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return specfun.klvnzo(nt,<NUM_LIT:1>),specfun.klvnzo(nt,<NUM_LIT:2>),specfun.klvnzo(nt,<NUM_LIT:3>),specfun.klvnzo(nt,<NUM_LIT:4>),specfun.klvnzo(nt,<NUM_LIT:5>),specfun.klvnzo(nt,<NUM_LIT:6>),specfun.klvnzo(nt,<NUM_LIT:7>),specfun.klvnzo(nt,<NUM_LIT:8>)<EOL>

Compute nt zeros of all the Kelvin functions returned in a
    length 8 tuple of arrays of length nt.
    The tuple containse the arrays of zeros of
    (ber, bei, ker, kei, ber', bei', ker', kei')


if not (isscalar(m) and isscalar(n) and isscalar(c)):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (n != floor(n)) or (m != floor(m)):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (n-m > <NUM_LIT>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>maxL = n-m+<NUM_LIT:1><EOL>return specfun.segv(m,n,c,<NUM_LIT:1>)[<NUM_LIT:1>][:maxL]<EOL>

Compute a sequence of characteristic values for the prolate
    spheroidal wave functions for mode m and n'=m..n and spheroidal
    parameter c.


if not (isscalar(m) and isscalar(n) and isscalar(c)):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (n != floor(n)) or (m != floor(m)):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (n-m > <NUM_LIT>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>maxL = n-m+<NUM_LIT:1><EOL>return specfun.segv(m,n,c,-<NUM_LIT:1>)[<NUM_LIT:1>][:maxL]<EOL>

Compute a sequence of characteristic values for the oblate
    spheroidal wave functions for mode m and n'=m..n and spheroidal
    parameter c.


return ellipkm1(<NUM_LIT:1> - asarray(m))<EOL>

Complete elliptic integral of the first kind

This function is defined as

.. math:: K(m) = \\int_0^{\\pi/2} [1 - m \\sin(t)^2]^{-1/2} dt

Parameters
----------
m : array_like
    The parameter of the elliptic integral.

Returns
-------
K : array_like
    Value of the elliptic integral.

Notes
-----
For more precision around point m = 1, use `ellipkm1`.

See Also
--------
ellipkm1 : Complete elliptic integral of the first kind around m = 1
ellipkinc : Incomplete elliptic integral of the first kind
ellipe : Complete elliptic integral of the second kind
ellipeinc : Incomplete elliptic integral of the second kind


s = a + b + <NUM_LIT:0.0><EOL>return (pi / <NUM_LIT:4>) * s / ellipkm1(<NUM_LIT:4> * a * b / s ** <NUM_LIT:2>)<EOL>

Arithmetic, Geometric Mean

    Start with a_0=a and b_0=b and iteratively compute

    a_{n+1} = (a_n+b_n)/2
    b_{n+1} = sqrt(a_n*b_n)

    until a_n=b_n.   The result is agm(a,b)

    agm(a,b)=agm(b,a)
    agm(a,a) = a
    min(a,b) < agm(a,b) < max(a,b)


def comb(N, k, exact=False, repetition=False):

if repetition:<EOL><INDENT>return comb(N + k - <NUM_LIT:1>, k, exact)<EOL><DEDENT>if exact:<EOL><INDENT>N = int(N)<EOL>k = int(k)<EOL>if (k > N) or (N < <NUM_LIT:0>) or (k < <NUM_LIT:0>):<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>val = <NUM_LIT:1><EOL>for j in xrange(min(k, N-k)):<EOL><INDENT>val = (val*(N-j))//(j+<NUM_LIT:1>)<EOL><DEDENT>return val<EOL><DEDENT>else:<EOL><INDENT>k,N = asarray(k), asarray(N)<EOL>cond = (k <= N) & (N >= <NUM_LIT:0>) & (k >= <NUM_LIT:0>)<EOL>vals = binom(N, k)<EOL>if isinstance(vals, np.ndarray):<EOL><INDENT>vals[~cond] = <NUM_LIT:0><EOL><DEDENT>elif not cond:<EOL><INDENT>vals = np.float64(<NUM_LIT:0>)<EOL><DEDENT>return vals<EOL><DEDENT>

The number of combinations of N things taken k at a time.

This is often expressed as "N choose k".

Parameters
----------
N : int, ndarray
    Number of things.
k : int, ndarray
    Number of elements taken.
exact : bool, optional
    If `exact` is False, then floating point precision is used, otherwise
    exact long integer is computed.
repetition : bool, optional
    If `repetition` is True, then the number of combinations with
    repetition is computed.

Returns
-------
val : int, ndarray
    The total number of combinations.

Notes
-----
- Array arguments accepted only for exact=False case.
- If k > N, N < 0, or k < 0, then a 0 is returned.

Examples
--------
>>> k = np.array([3, 4])
>>> n = np.array([10, 10])
>>> sc.comb(n, k, exact=False)
array([ 120.,  210.])
>>> sc.comb(10, 3, exact=True)
120L
>>> sc.comb(10, 3, exact=True, repetition=True)
220L


if exact:<EOL><INDENT>if (k > N) or (N < <NUM_LIT:0>) or (k < <NUM_LIT:0>):<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>val = <NUM_LIT:1><EOL>for i in xrange(N - k + <NUM_LIT:1>, N + <NUM_LIT:1>):<EOL><INDENT>val *= i<EOL><DEDENT>return val<EOL><DEDENT>else:<EOL><INDENT>k, N = asarray(k), asarray(N)<EOL>cond = (k <= N) & (N >= <NUM_LIT:0>) & (k >= <NUM_LIT:0>)<EOL>vals = poch(N - k + <NUM_LIT:1>, k)<EOL>if isinstance(vals, np.ndarray):<EOL><INDENT>vals[~cond] = <NUM_LIT:0><EOL><DEDENT>elif not cond:<EOL><INDENT>vals = np.float64(<NUM_LIT:0>)<EOL><DEDENT>return vals<EOL><DEDENT>

Permutations of N things taken k at a time, i.e., k-permutations of N.

It's also known as "partial permutations".

Parameters
----------
N : int, ndarray
    Number of things.
k : int, ndarray
    Number of elements taken.
exact : bool, optional
    If `exact` is False, then floating point precision is used, otherwise
    exact long integer is computed.

Returns
-------
val : int, ndarray
    The number of k-permutations of N.

Notes
-----
- Array arguments accepted only for exact=False case.
- If k > N, N < 0, or k < 0, then a 0 is returned.

Examples
--------
>>> k = np.array([3, 4])
>>> n = np.array([10, 10])
>>> perm(n, k)
array([  720.,  5040.])
>>> perm(10, 3, exact=True)
720


if exact:<EOL><INDENT>if n < <NUM_LIT:0>:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>val = <NUM_LIT:1><EOL>for k in xrange(<NUM_LIT:1>,n+<NUM_LIT:1>):<EOL><INDENT>val *= k<EOL><DEDENT>return val<EOL><DEDENT>else:<EOL><INDENT>n = asarray(n)<EOL>vals = gamma(n+<NUM_LIT:1>)<EOL>return where(n >= <NUM_LIT:0>,vals,<NUM_LIT:0>)<EOL><DEDENT>

The factorial function, n! = special.gamma(n+1).

If exact is 0, then floating point precision is used, otherwise
exact long integer is computed.

- Array argument accepted only for exact=False case.
- If n<0, the return value is 0.

Parameters
----------
n : int or array_like of ints
    Calculate ``n!``.  Arrays are only supported with `exact` set
    to False.  If ``n < 0``, the return value is 0.
exact : bool, optional
    The result can be approximated rapidly using the gamma-formula
    above.  If `exact` is set to True, calculate the
    answer exactly using integer arithmetic. Default is False.

Returns
-------
nf : float or int
    Factorial of `n`, as an integer or a float depending on `exact`.

Examples
--------
>>> arr = np.array([3,4,5])
>>> sc.factorial(arr, exact=False)
array([   6.,   24.,  120.])
>>> sc.factorial(5, exact=True)
120L


if exact:<EOL><INDENT>if n < -<NUM_LIT:1>:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>if n <= <NUM_LIT:0>:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT>val = <NUM_LIT:1><EOL>for k in xrange(n,<NUM_LIT:0>,-<NUM_LIT:2>):<EOL><INDENT>val *= k<EOL><DEDENT>return val<EOL><DEDENT>else:<EOL><INDENT>n = asarray(n)<EOL>vals = zeros(n.shape,'<STR_LIT:d>')<EOL>cond1 = (n % <NUM_LIT:2>) & (n >= -<NUM_LIT:1>)<EOL>cond2 = (<NUM_LIT:1>-(n % <NUM_LIT:2>)) & (n >= -<NUM_LIT:1>)<EOL>oddn = extract(cond1,n)<EOL>evenn = extract(cond2,n)<EOL>nd2o = oddn / <NUM_LIT><EOL>nd2e = evenn / <NUM_LIT><EOL>place(vals,cond1,gamma(nd2o+<NUM_LIT:1>)/sqrt(pi)*pow(<NUM_LIT>,nd2o+<NUM_LIT:0.5>))<EOL>place(vals,cond2,gamma(nd2e+<NUM_LIT:1>) * pow(<NUM_LIT>,nd2e))<EOL>return vals<EOL><DEDENT>

Double factorial.

This is the factorial with every second value skipped, i.e.,
``7!! = 7 * 5 * 3 * 1``.  It can be approximated numerically as::

  n!! = special.gamma(n/2+1)*2**((m+1)/2)/sqrt(pi)  n odd
      = 2**(n/2) * (n/2)!                           n even

Parameters
----------
n : int or array_like
    Calculate ``n!!``.  Arrays are only supported with `exact` set
    to False.  If ``n < 0``, the return value is 0.
exact : bool, optional
    The result can be approximated rapidly using the gamma-formula
    above (default).  If `exact` is set to True, calculate the
    answer exactly using integer arithmetic.

Returns
-------
nff : float or int
    Double factorial of `n`, as an int or a float depending on
    `exact`.

Examples
--------
>>> factorial2(7, exact=False)
array(105.00000000000001)
>>> factorial2(7, exact=True)
105L


if exact:<EOL><INDENT>if n < <NUM_LIT:1>-k:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>if n <= <NUM_LIT:0>:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT>val = <NUM_LIT:1><EOL>for j in xrange(n,<NUM_LIT:0>,-k):<EOL><INDENT>val = val*j<EOL><DEDENT>return val<EOL><DEDENT>else:<EOL><INDENT>raise NotImplementedError<EOL><DEDENT>

n(!!...!)  = multifactorial of order k
k times

Parameters
----------
n : int
    Calculate multifactorial. If `n` < 0, the return value is 0.
exact : bool, optional
    If exact is set to True, calculate the answer exactly using
    integer arithmetic.

Returns
-------
val : int
    Multi factorial of `n`.

Raises
------
NotImplementedError
    Raises when exact is False

Examples
--------
>>> sc.factorialk(5, 1, exact=True)
120L
>>> sc.factorialk(5, 3, exact=True)
10L