Current File : //proc/self/root/proc/self/root/lib64/python2.7/site-packages/numpy/lib/arraypad.pyc
�
E�`Qc@s�dZddlZdgZd�Zd�Zd�Zd�Zd�Zd	�Z	d
�Z
d�Zd�Zd
�Z
d�Zd�Zd�Zd�Zdd�ZdS(sk
The arraypad module contains a group of functions to pad values onto the edges
of an n-dimensional array.
i����NtpadcCs4|||d*|ddkr0|||d)n|S(s
    Private function which creates the padded vector.

    Parameters
    ----------
    vector : ndarray of rank 1, length N + pad_tuple[0] + pad_tuple[1]
        Input vector including blank padded values.  `N` is the lenth of the
        original vector.
    pad_tuple : tuple
        This tuple represents the (before, after) width of the padding along
        this particular iaxis.
    before_val : scalar or ndarray of rank 1, length pad_tuple[0]
        This is the value(s) that will pad the beginning of `vector`.
    after_val : scalar or ndarray of rank 1, length pad_tuple[1]
        This is the value(s) that will pad the end of the `vector`.

    Returns
    -------
    _create_vector : ndarray
        Vector with before_val and after_val replacing the blank pad values.
    ii((tvectort	pad_tuplet
before_valt	after_val((s8/usr/lib64/python2.7/site-packages/numpy/lib/arraypad.pyt_create_vectorsc
Cs�d}ttj|��}t|t�r@||ff|}n<t|ttf�r�t|dttf�r�t|�|kr�|}x�|D]4}t|�dkr�d}t||f��q�q�Wn�t|ttf�r)t|dtt	t
f�r)t|�dkr)|d|dff|}nSt|ttf�r|t|dtt	t
f�r|t|�dkr||f|}n|dkr�d}t||f��n|S(s+
    Private function which does some checks and normalizes the possibly
    much simpler representations of 'pad_width', 'stat_length',
    'constant_values', 'end_values'.

    Parameters
    ----------
    narray : ndarray
        Input ndarray
    shape : {sequence, int}, optional
        The width of padding (pad_width) or the number of elements on the
        edge of the narray used for statistics (stat_length).
        ((before_1, after_1), ... (before_N, after_N)) unique number of
        elements for each axis where `N` is rank of `narray`.
        ((before, after),) yields same before and after constants for each
        axis.
        (constant,) or int is a shortcut for before = after = constant for
        all axes.

    Returns
    -------
    _normalize_shape : tuple of tuples
        int                               => ((int, int), (int, int), ...)
        [[int1, int2], [int3, int4], ...] => ((int1, int2), (int3, int4), ...)
        ((int1, int2), (int3, int4), ...) => no change
        [[int1, int2], ]                  => ((int1, int2), (int1, int2), ...]
        ((int1, int2), )                  => ((int1, int2), (int1, int2), ...)
        [[int ,     ), )                  => ((int, int), (int, int), ...)
        ((int ,     ), )                  => ((int, int), (int, int), ...)
    iis/Unable to create correctly shaped tuple from %siN(tNonetlentnptshapet
isinstancetintttupletlistt
ValueErrortfloattlong(tnarrayR	tnormshptshapelentitfmt((s8/usr/lib64/python2.7/site-packages/numpy/lib/arraypad.pyt_normalize_shape+s0
cCsuttj|��}t||�}xJ|D]B}|ddksQ|ddkr+d}t||f��q+q+W|S(s�
    Private function which does some checks and reformats pad_width and
    stat_length using _normalize_shape.

    Parameters
    ----------
    narray : ndarray
        Input ndarray
    number_elements : {sequence, int}, optional
        The width of padding (pad_width) or the number of elements on the edge
        of the narray used for statistics (stat_length).
        ((before_1, after_1), ... (before_N, after_N)) unique number of
        elements for each axis.
        ((before, after),) yields same before and after constants for each
        axis.
        (constant,) or int is a shortcut for before = after = constant for all
        axes.

    Returns
    -------
    _validate_lengths : tuple of tuples
        int                               => ((int, int), (int, int), ...)
        [[int1, int2], [int3, int4], ...] => ((int1, int2), (int3, int4), ...)
        ((int1, int2), (int3, int4), ...) => no change
        [[int1, int2], ]                  => ((int1, int2), (int1, int2), ...]
        ((int1, int2), )                  => ((int1, int2), (int1, int2), ...)
        [[int ,     ), )                  => ((int, int), (int, int), ...)
        ((int ,     ), )                  => ((int, int), (int, int), ...)
    iis"%s cannot contain negative values.(RRR	RR(Rtnumber_elementsRRRR((s8/usr/lib64/python2.7/site-packages/numpy/lib/arraypad.pyt_validate_lengthsds
 c
Cs|d}|dkr d}n||d|!}||d|!}|dr|d|}t|dt|��}t|dt|��}	tjd�}tjd�}|ddkr�||d|d|!}n|ddkr||d|	|!}qn||fS(s�
    Returns the portion of the vector required for any statistic.

    Parameters
    ----------
    vector : ndarray
        Input vector that already includes empty padded values.
    pad_tuple : tuple
        This tuple represents the (before, after) width of the padding
        along this particular iaxis.
    iaxis : int
        The axis currently being looped across.
    kwargs : keyword arguments
        Keyword arguments.  Only 'stat_length' is used.  'stat_length'
        defaults to the entire vector if not supplied.

    Return
    ------
    _create_stat_vectors : ndarray
        The values from the original vector that will be used to calculate
        the statistic.
    iitstat_lengthN(RtminRRtarange(
RRtiaxistkwargstpt1tsbvectsavecRtsl0tsl1((s8/usr/lib64/python2.7/site-packages/numpy/lib/arraypad.pyt_create_stat_vectors�s 	
cCs:t||||�\}}t||t|�t|��S(sh
    Private function to calculate the before/after vectors for pad_maximum.

    Parameters
    ----------
    vector : ndarray
        Input vector that already includes empty padded values.
    pad_tuple : tuple
        This tuple represents the (before, after) width of the padding
        along this particular iaxis.
    iaxis : int
        The axis currently being looped across.
    kwargs : keyword arguments
        Keyword arguments.  Only 'stat_length' is used.  'stat_length'
        defaults to the entire vector if not supplied.

    Return
    ------
    _maximum : ndarray
        Padded vector
    (R#Rtmax(RRRRRR ((s8/usr/lib64/python2.7/site-packages/numpy/lib/arraypad.pyt_maximum�scCs:t||||�\}}t||t|�t|��S(sh
    Private function to calculate the before/after vectors for pad_minimum.

    Parameters
    ----------
    vector : ndarray
        Input vector that already includes empty padded values.
    pad_tuple : tuple
        This tuple represents the (before, after) width of the padding
        along this particular iaxis.
    iaxis : int
        The axis currently being looped across.
    kwargs : keyword arguments
        Keyword arguments.  Only 'stat_length' is used.  'stat_length'
        defaults to the entire vector if not supplied.

    Return
    ------
    _minimum : ndarray
        Padded vector
    (R#RR(RRRRRR ((s8/usr/lib64/python2.7/site-packages/numpy/lib/arraypad.pyt_minimum�scCs@t||||�\}}t||tj|�tj|��S(sf
    Private function to calculate the before/after vectors for pad_median.

    Parameters
    ----------
    vector : ndarray
        Input vector that already includes empty padded values.
    pad_tuple : tuple
        This tuple represents the (before, after) width of the padding
        along this particular iaxis.
    iaxis : int
        The axis currently being looped across.
    kwargs : keyword arguments
        Keyword arguments.  Only 'stat_length' is used.  'stat_length'
        defaults to the entire vector if not supplied.

    Return
    ------
    _median : ndarray
        Padded vector
    (R#RRtmedian(RRRRRR ((s8/usr/lib64/python2.7/site-packages/numpy/lib/arraypad.pyt_median�scCs@t||||�\}}t||tj|�tj|��S(sb
    Private function to calculate the before/after vectors for pad_mean.

    Parameters
    ----------
    vector : ndarray
        Input vector that already includes empty padded values.
    pad_tuple : tuple
        This tuple represents the (before, after) width of the padding
        along this particular iaxis.
    iaxis : int
        The axis currently being looped across.
    kwargs : keyword arguments
        Keyword arguments.  Only 'stat_length' is used.  'stat_length'
        defaults to the entire vector if not supplied.

    Return
    ------
    _mean : ndarray
        Padded vector
    (R#RRtaverage(RRRRRR ((s8/usr/lib64/python2.7/site-packages/numpy/lib/arraypad.pyt_meanscCs)|d|}t|||d|d�S(s5
    Private function to calculate the before/after vectors for
    pad_constant.

    Parameters
    ----------
    vector : ndarray
        Input vector that already includes empty padded values.
    pad_tuple : tuple
        This tuple represents the (before, after) width of the padding
        along this particular iaxis.
    iaxis : int
        The axis currently being looped across.
    kwargs : keyword arguments
        Keyword arguments.  Need 'constant_values' keyword argument.

    Return
    ------
    _constant : ndarray
        Padded vector
    tconstant_valuesii(R(RRRRt	nconstant((s8/usr/lib64/python2.7/site-packages/numpy/lib/arraypad.pyt	_constant#sc
CsG|d|}||d|dt|d�}||dd|dt|d�}tj|df�|d}|j|j�}x0tt|��D]}||||||<q�Wtj|df�|d}	|	j|j�}	x0tt|	��D]}|	||||	|<qW|	ddd�}	t||||	�S(sF
    Private function to calculate the before/after vectors for
    pad_linear_ramp.

    Parameters
    ----------
    vector : ndarray
        Input vector that already includes empty padded values.
    pad_tuple : tuple
        This tuple represents the (before, after) width of the padding
        along this particular iaxis.
    iaxis : int
        The axis currently being looped across.  Not used in _linear_ramp.
    kwargs : keyword arguments
        Keyword arguments. Not used in _linear_ramp.

    Return
    ------
    _linear_ramp : ndarray
        Padded vector
    t
end_valuesiiNi����(RRtonestastypetdtypetrangeRR(
RRRRR.tbefore_deltatafter_deltat
before_vectorRtafter_vector((s8/usr/lib64/python2.7/site-packages/numpy/lib/arraypad.pyt_linear_ramp=scCs6|ddkr$||dd!}n||d|d!}|ddd�}tjtj|dd!|f�|d�ddd�}tjtj|dd!|f�|d�}|ddkr�n^|ddkr	d||d|}d||dd|}ntd	d|df��t||||�S(
s2
    Private function to calculate the before/after vectors for pad_reflect.

    Parameters
    ----------
    vector : ndarray
        Input vector that already includes empty padded values.
    pad_tuple : tuple
        This tuple represents the (before, after) width of the padding
        along this particular iaxis.
    iaxis : int
        The axis currently being looped across.  Not used in _reflect.
    kwargs : keyword arguments
        Keyword arguments. Not used in _reflect.

    Return
    ------
    _reflect : ndarray
        Padded vector
    iiNi����treflect_typeteventoddis,The keyword '%s' cannot have the value '%s'.(RRtresizetconcatenateRR(RRRRR6treverseR5((s8/usr/lib64/python2.7/site-packages/numpy/lib/arraypad.pyt_reflectgs$- cCs/|ddkr$||dd!}n||d|d!}tjtj||ddd�f�|d�ddd�}tjtj|ddd�|f�|d�}|ddkr�n^|ddkrd||d|}d||dd|}ntd	d|df��t||||�S(
s>
    Private function to calculate the before/after vectors for
    pad_symmetric.

    Parameters
    ----------
    vector : ndarray
        Input vector that already includes empty padded values.
    pad_tuple : tuple
        This tuple represents the (before, after) width of the padding
        along this particular iaxis.
    iaxis : int
        The axis currently being looped across.  Not used in _symmetric.
    kwargs : keyword arguments
        Keyword arguments. Not used in _symmetric.

    Return
    ------
    _symmetric : ndarray
        Padded vector
    iiNi����R8R9R:is,The keyword '%s' cannot have the value '%s'.(RRR;R<RR(RRRRR6R5((s8/usr/lib64/python2.7/site-packages/numpy/lib/arraypad.pyt
_symmetric�s0cCs�|ddkr$||dd!}n||d|d!}tj|ddd�|d�ddd�}tj||d�}t||||�S(s&
    Private function to calculate the before/after vectors for pad_wrap.

    Parameters
    ----------
    vector : ndarray
        Input vector that already includes empty padded values.
    pad_tuple : tuple
        This tuple represents the (before, after) width of the padding
        along this particular iaxis.
    iaxis : int
        The axis currently being looped across.  Not used in _wrap.
    kwargs : keyword arguments
        Keyword arguments. Not used in _wrap.

    Return
    ------
    _wrap : ndarray
        Padded vector
    iiNi����(RRR;R(RRRRR6R5((s8/usr/lib64/python2.7/site-packages/numpy/lib/arraypad.pyt_wrap�s0cCs(t||||d||dd�S(s&
    Private function to calculate the before/after vectors for pad_edge.

    Parameters
    ----------
    vector : ndarray
        Input vector that already includes empty padded values.
    pad_tuple : tuple
        This tuple represents the (before, after) width of the padding
        along this particular iaxis.
    iaxis : int
        The axis currently being looped across.  Not used in _edge.
    kwargs : keyword arguments
        Keyword arguments. Not used in _edge.

    Return
    ------
    _edge : ndarray
        Padded vector
    ii(R(RRRR((s8/usr/lib64/python2.7/site-packages/numpy/lib/arraypad.pyt_edge�scKs�tj|�}t||�}i
td6td6td6td6td6td6t	d6t
d6td	6td
6}i
dgd6gd6dgd6d
gd6d
gd6d
gd6d
gd6dgd6dgd	6gd
6}idd
6dd6dd6dd6}t|t�r�||}x;|D]3}	|	||krtd|	||f��qqWx&||D]}
|j|
||
�qRWx�|D]\}|d
kr�||r�t|||�||<n|dkrwt|||�||<qwqwWn.|dkrtd|j�f��n|}tt|j��}g|D]}tj||�^q$}
g|D]0}t||d||d|j|�^qJ}tj|j�|
}tj|�j|j�}|||<x.|D]&}tj|||||||�q�W|S(s�
    Pads an array.

    Parameters
    ----------
    array : array_like of rank N
        Input array
    pad_width : {sequence, int}
        Number of values padded to the edges of each axis.
        ((before_1, after_1), ... (before_N, after_N)) unique pad widths
        for each axis.
        ((before, after),) yields same before and after pad for each axis.
        (pad,) or int is a shortcut for before = after = pad width for all
        axes.
    mode : {str, function}
        One of the following string values or a user supplied function.

        'constant'      Pads with a constant value.
        'edge'          Pads with the edge values of array.
        'linear_ramp'   Pads with the linear ramp between end_value and the
                        array edge value.
        'maximum'       Pads with the maximum value of all or part of the
                        vector along each axis.
        'mean'          Pads with the mean value of all or part of the
                        vector along each axis.
        'median'        Pads with the median value of all or part of the
                        vector along each axis.
        'minimum'       Pads with the minimum value of all or part of the
                        vector along each axis.
        'reflect'       Pads with the reflection of the vector mirrored on
                        the first and last values of the vector along each
                        axis.
        'symmetric'     Pads with the reflection of the vector mirrored
                        along the edge of the array.
        'wrap'          Pads with the wrap of the vector along the axis.
                        The first values are used to pad the end and the
                        end values are used to pad the beginning.
        <function>      Padding function, see Notes.
    stat_length : {sequence, int}, optional
        Used in 'maximum', 'mean', 'median', and 'minimum'.  Number of
        values at edge of each axis used to calculate the statistic value.

        ((before_1, after_1), ... (before_N, after_N)) unique statistic
        lengths for each axis.

        ((before, after),) yields same before and after statistic lengths
        for each axis.

        (stat_length,) or int is a shortcut for before = after = statistic
        length for all axes.

        Default is ``None``, to use the entire axis.
    constant_values : {sequence, int}, optional
        Used in 'constant'.  The values to set the padded values for each
        axis.

        ((before_1, after_1), ... (before_N, after_N)) unique pad constants
        for each axis.

        ((before, after),) yields same before and after constants for each
        axis.

        (constant,) or int is a shortcut for before = after = constant for
        all axes.

        Default is 0.
    end_values : {sequence, int}, optional
        Used in 'linear_ramp'.  The values used for the ending value of the
        linear_ramp and that will form the edge of the padded array.

        ((before_1, after_1), ... (before_N, after_N)) unique end values
        for each axis.

        ((before, after),) yields same before and after end values for each
        axis.

        (constant,) or int is a shortcut for before = after = end value for
        all axes.

        Default is 0.
    reflect_type : str {'even', 'odd'}, optional
        Used in 'reflect', and 'symmetric'.  The 'even' style is the
        default with an unaltered reflection around the edge value.  For
        the 'odd' style, the extented part of the array is created by
        subtracting the reflected values from two times the edge value.

    Returns
    -------
    pad : ndarray
        Padded array of rank equal to `array` with shape increased
        according to `pad_width`.

    Notes
    -----
    .. versionadded:: 1.7.0

    For an array with rank greater than 1, some of the padding of later
    axes is calculated from padding of previous axes.  This is easiest to
    think about with a rank 2 array where the corners of the padded array
    are calculated by using padded values from the first axis.

    The padding function, if used, should return a rank 1 array equal in
    length to the vector argument with padded values replaced. It has the
    following signature:

        padding_func(vector, iaxis_pad_width, iaxis, **kwargs)

    where

        vector: ndarray
            A rank 1 array already padded with zeros.  Padded values are
            vector[:pad_tuple[0]] and vector[-pad_tuple[1]:].
        iaxis_pad_width: tuple
            A 2-tuple of ints, iaxis_pad_width[0] represents the number of
            values padded at the beginning of vector where
            iaxis_pad_width[1] represents the number of values padded at
            the end of vector.
        iaxis : int
            The axis currently being calculated.
        kwargs : misc
            Any keyword arguments the function requires.

    Examples
    --------
    >>> a = [1, 2, 3, 4, 5]
    >>> np.lib.pad(a, (2,3), 'constant', constant_values=(4,6))
    array([4, 4, 1, 2, 3, 4, 5, 6, 6, 6])

    >>> np.lib.pad(a, (2,3), 'edge')
    array([1, 1, 1, 2, 3, 4, 5, 5, 5, 5])

    >>> np.lib.pad(a, (2,3), 'linear_ramp', end_values=(5,-4))
    array([ 5,  3,  1,  2,  3,  4,  5,  2, -1, -4])

    >>> np.lib.pad(a, (2,), 'maximum')
    array([5, 5, 1, 2, 3, 4, 5, 5, 5])

    >>> np.lib.pad(a, (2,), 'mean')
    array([3, 3, 1, 2, 3, 4, 5, 3, 3])

    >>> np.lib.pad(a, (2,), 'median')
    array([3, 3, 1, 2, 3, 4, 5, 3, 3])

    >>> a = [[1,2], [3,4]]
    >>> np.lib.pad(a, ((3, 2), (2, 3)), 'minimum')
    array([[1, 1, 1, 2, 1, 1, 1],
           [1, 1, 1, 2, 1, 1, 1],
           [1, 1, 1, 2, 1, 1, 1],
           [1, 1, 1, 2, 1, 1, 1],
           [3, 3, 3, 4, 3, 3, 3],
           [1, 1, 1, 2, 1, 1, 1],
           [1, 1, 1, 2, 1, 1, 1]])

    >>> a = [1, 2, 3, 4, 5]
    >>> np.lib.pad(a, (2,3), 'reflect')
    array([3, 2, 1, 2, 3, 4, 5, 4, 3, 2])

    >>> np.lib.pad(a, (2,3), 'reflect', reflect_type='odd')
    array([-1,  0,  1,  2,  3,  4,  5,  6,  7,  8])

    >>> np.lib.pad(a, (2,3), 'symmetric')
    array([2, 1, 1, 2, 3, 4, 5, 5, 4, 3])

    >>> np.lib.pad(a, (2,3), 'symmetric', reflect_type='odd')
    array([0, 1, 1, 2, 3, 4, 5, 5, 6, 7])

    >>> np.lib.pad(a, (2,3), 'wrap')
    array([4, 5, 1, 2, 3, 4, 5, 1, 2, 3])

    >>> def padwithtens(vector, pad_width, iaxis, kwargs):
    ...     vector[:pad_width[0]] = 10
    ...     vector[-pad_width[1]:] = 10
    ...     return vector

    >>> a = np.arange(6)
    >>> a = a.reshape((2,3))

    >>> np.lib.pad(a, 2, padwithtens)
    array([[10, 10, 10, 10, 10, 10, 10],
           [10, 10, 10, 10, 10, 10, 10],
           [10, 10,  0,  1,  2, 10, 10],
           [10, 10,  3,  4,  5, 10, 10],
           [10, 10, 10, 10, 10, 10, 10],
           [10, 10, 10, 10, 10, 10, 10]])
    tconstanttedgetlinear_ramptmaximumtmeanR'tminimumtreflectt	symmetrictwrapR+R.RR8iR9s%%s keyword not in allowed keywords %ss/Keyword "mode" must be a function or one of %s.N(s
end_valuessconstant_values(RtarrayRR-RAR7R%R*R(R&R>R?R@RR
tstrRt
setdefaultRtkeysR2RR	tsumtslicetzerosR0R1tapply_along_axis(RKt	pad_widthtmodeRRtmodefunct
allowedkwargst
kwdefaultstfunctiontkeytkwRtrankttotal_dim_increaset
offset_slicest	new_shapetnewmatR((s8/usr/lib64/python2.7/site-packages/numpy/lib/arraypad.pyR�sz�













!&:

	(t__doc__tnumpyRt__all__RRRR#R%R&R(R*R-R7R>R?R@RARR(((s8/usr/lib64/python2.7/site-packages/numpy/lib/arraypad.pyt<module>s"			9	'	.						*	/	+