ó
Ë½÷Xc           @` sƒ   d  Z  d d l m Z m Z m Z d d l Z d d d d d „ Z d d „ Z	 d d „ Z
 d d „ Z d d	 „ Z d d
 „ Z d S(   s-   
Functions for acting on a axis of an array.
i    (   t   divisiont   print_functiont   absolute_importNiÿÿÿÿc         C` s:   t  d ƒ g |  j } t  | | | ƒ | | <|  | } | S(   sÛ  Take a slice along axis 'axis' from 'a'.

    Parameters
    ----------
    a : numpy.ndarray
        The array to be sliced.
    start, stop, step : int or None
        The slice parameters.
    axis : int, optional
        The axis of `a` to be sliced.

    Examples
    --------
    >>> a = array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
    >>> axis_slice(a, start=0, stop=1, axis=1)
    array([[1],
           [4],
           [7]])
    >>> axis_slice(a, start=1, axis=0)
    array([[4, 5, 6],
           [7, 8, 9]])

    Notes
    -----
    The keyword arguments start, stop and step are used by calling
    slice(start, stop, step).  This implies axis_slice() does not
    handle its arguments the exacty the same as indexing.  To select
    a single index k, for example, use
        axis_slice(a, start=k, stop=k+1)
    In this case, the length of the axis 'axis' in the result will
    be 1; the trivial dimension is not removed. (Use numpy.squeeze()
    to remove trivial axes.)
    N(   t   slicet   Nonet   ndim(   t   at   startt   stopt   stept   axist   a_slicet   b(    (    s7   /tmp/pip-build-7oUkmx/scipy/scipy/signal/_arraytools.pyt
   axis_slice	   s    "
c         C` s   t  |  d d d | ƒS(   se   Reverse the 1-d slices of `a` along axis `axis`.

    Returns axis_slice(a, step=-1, axis=axis).
    R	   iÿÿÿÿR
   (   R   (   R   R
   (    (    s7   /tmp/pip-build-7oUkmx/scipy/scipy/signal/_arraytools.pyt   axis_reverse1   s    c      
   C` s  | d k  r |  S| |  j  | d k rO t d d | |  j  | d f ƒ ‚ n  t |  d d d d d | ƒ} t |  d | d d d d	 d | ƒ} t |  d d	 d | ƒ} t |  d d
 d | d d d	 d | ƒ} t j d | | |  d | | f d | ƒ} | S(   s,  
    Odd extension at the boundaries of an array

    Generate a new ndarray by making an odd extension of `x` along an axis.

    Parameters
    ----------
    x : ndarray
        The array to be extended.
    n : int
        The number of elements by which to extend `x` at each end of the axis.
    axis : int, optional
        The axis along which to extend `x`.  Default is -1.

    Examples
    --------
    >>> from scipy.signal._arraytools import odd_ext
    >>> a = np.array([[1, 2, 3, 4, 5], [0, 1, 4, 9, 16]])
    >>> odd_ext(a, 2)
    array([[-1,  0,  1,  2,  3,  4,  5,  6,  7],
           [-4, -1,  0,  1,  4,  9, 16, 23, 28]])

    Odd extension is a "180 degree rotation" at the endpoints of the original
    array:

    >>> t = np.linspace(0, 1.5, 100)
    >>> a = 0.9 * np.sin(2 * np.pi * t**2)
    >>> b = odd_ext(a, 40)
    >>> import matplotlib.pyplot as plt
    >>> plt.plot(arange(-40, 140), b, 'b', lw=1, label='odd extension')
    >>> plt.plot(arange(100), a, 'r', lw=2, label='original')
    >>> plt.legend(loc='best')
    >>> plt.show()
    i   s(   The extension length n (%d) is too big. s0   It must not exceed x.shape[axis]-1, which is %d.R   i    R   R
   R	   iÿÿÿÿiþÿÿÿi   (   t   shapet
   ValueErrorR   t   npt   concatenate(   t   xt   nR
   t   left_endt   left_extt	   right_endt	   right_extt   ext(    (    s7   /tmp/pip-build-7oUkmx/scipy/scipy/signal/_arraytools.pyt   odd_ext9   s    #$)	c      
   C` s¾   | d k  r |  S| |  j  | d k rO t d d | |  j  | d f ƒ ‚ n  t |  d | d d d d d	 | ƒ} t |  d d
 d | d d d d	 | ƒ} t j | |  | f d	 | ƒ} | S(   s)  
    Even extension at the boundaries of an array

    Generate a new ndarray by making an even extension of `x` along an axis.

    Parameters
    ----------
    x : ndarray
        The array to be extended.
    n : int
        The number of elements by which to extend `x` at each end of the axis.
    axis : int, optional
        The axis along which to extend `x`.  Default is -1.

    Examples
    --------
    >>> from scipy.signal._arraytools import even_ext
    >>> a = np.array([[1, 2, 3, 4, 5], [0, 1, 4, 9, 16]])
    >>> even_ext(a, 2)
    array([[ 3,  2,  1,  2,  3,  4,  5,  4,  3],
           [ 4,  1,  0,  1,  4,  9, 16,  9,  4]])

    Even extension is a "mirror image" at the boundaries of the original array:

    >>> t = np.linspace(0, 1.5, 100)
    >>> a = 0.9 * np.sin(2 * np.pi * t**2)
    >>> b = even_ext(a, 40)
    >>> import matplotlib.pyplot as plt
    >>> plt.plot(arange(-40, 140), b, 'b', lw=1, label='even extension')
    >>> plt.plot(arange(100), a, 'r', lw=2, label='original')
    >>> plt.legend(loc='best')
    >>> plt.show()
    i   s(   The extension length n (%d) is too big. s0   It must not exceed x.shape[axis]-1, which is %d.R   R   i    R	   iÿÿÿÿR
   iþÿÿÿi   (   R   R   R   R   R   (   R   R   R
   R   R   R   (    (    s7   /tmp/pip-build-7oUkmx/scipy/scipy/signal/_arraytools.pyt   even_extm   s    "$)			c   
      C` s®   | d k  r |  St  |  d d d d d | ƒ} d g |  j } | | | <t j | d |  j ƒ} | | } t  |  d d d | ƒ} | | } t j | |  | f d | ƒ}	 |	 S(   s“  
    Constant extension at the boundaries of an array

    Generate a new ndarray that is a constant extension of `x` along an axis.

    The extension repeats the values at the first and last element of
    the axis.

    Parameters
    ----------
    x : ndarray
        The array to be extended.
    n : int
        The number of elements by which to extend `x` at each end of the axis.
    axis : int, optional
        The axis along which to extend `x`.  Default is -1.

    Examples
    --------
    >>> from scipy.signal._arraytools import const_ext
    >>> a = np.array([[1, 2, 3, 4, 5], [0, 1, 4, 9, 16]])
    >>> const_ext(a, 2)
    array([[ 1,  1,  1,  2,  3,  4,  5,  5,  5],
           [ 0,  0,  0,  1,  4,  9, 16, 16, 16]])

    Constant extension continues with the same values as the endpoints of the
    array:

    >>> t = np.linspace(0, 1.5, 100)
    >>> a = 0.9 * np.sin(2 * np.pi * t**2)
    >>> b = const_ext(a, 40)
    >>> import matplotlib.pyplot as plt
    >>> plt.plot(arange(-40, 140), b, 'b', lw=1, label='constant extension')
    >>> plt.plot(arange(100), a, 'r', lw=2, label='original')
    >>> plt.legend(loc='best')
    >>> plt.show()
    i   R   i    R   R
   t   dtypeiÿÿÿÿ(   R   R   R   t   onesR   R   (
   R   R   R
   R   t
   ones_shapeR   R   R   R   R   (    (    s7   /tmp/pip-build-7oUkmx/scipy/scipy/signal/_arraytools.pyt	   const_extž   s    &


			c         C` sc   | d k  r |  St  |  j ƒ } | | | <t j | d |  j ƒ} t j | |  | f d | ƒ} | S(   s˜  
    Zero padding at the boundaries of an array

    Generate a new ndarray that is a zero padded extension of `x` along
    an axis.

    Parameters
    ----------
    x : ndarray
        The array to be extended.
    n : int
        The number of elements by which to extend `x` at each end of the
        axis.
    axis : int, optional
        The axis along which to extend `x`.  Default is -1.

    Examples
    --------
    >>> from scipy.signal._arraytools import zero_ext
    >>> a = np.array([[1, 2, 3, 4, 5], [0, 1, 4, 9, 16]])
    >>> zero_ext(a, 2)
    array([[ 0,  0,  1,  2,  3,  4,  5,  0,  0],
           [ 0,  0,  0,  1,  4,  9, 16,  0,  0]])
    i   R   R
   (   t   listR   R   t   zerosR   R   (   R   R   R
   t   zeros_shapeR!   R   (    (    s7   /tmp/pip-build-7oUkmx/scipy/scipy/signal/_arraytools.pyt   zero_extÔ   s    
(   t   __doc__t
   __future__R    R   R   t   numpyR   R   R   R   R   R   R   R#   (    (    (    s7   /tmp/pip-build-7oUkmx/scipy/scipy/signal/_arraytools.pyt   <module>   s   (416