Submit
Path:
~
/
/
proc
/
thread-self
/
root
/
opt
/
alt
/
python35
/
lib64
/
python3.5
/
site-packages
/
scipy
/
signal
/
__pycache__
/
File Content:
_arraytools.cpython-35.opt-1.pyc
�<WW � @ s� d Z d d l m Z m Z m Z d d l Z d d d d d d � Z d d d � Z d d d � Z d d d � Z d d d � Z d S)z- Functions for acting on a axis of an array. � )�division�print_function�absolute_importN� c C s: t d � g | j } t | | | � | | <| | } | S)a� 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)�slice�ndim)�a�start�stop�step�axisZa_slice�b� r �/_arraytools.py� axis_slice s " r c C s t | d d d | �S)zeReverse the 1-d slices of `a` along axis `axis`. Returns axis_slice(a, step=-1, axis=axis). r r r ���)r )r r r r r �axis_reverse1 s r c C s | d k r | S| | j | d k rL t d d | | j | d f � � 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)a5 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 -------- >>> a = array([[1.0,2.0,3.0,4.0,5.0], [0.0, 1.0, 4.0, 9.0, 16.0]]) >>> _odd_ext(a, 2) array([[-1., 0., 1., 2., 3., 4., 5., 6., 7.], [-4., -1, 0., 1., 4., 9., 16., 23., 28.]]) r z(The extension length n (%d) is too big. z0It must not exceed x.shape[axis]-1, which is %d.r r r r r � r r ���r )�shape� ValueErrorr �np�concatenate)�x�nr �left_end�left_ext� right_end� right_ext�extr r r �odd_ext9 s $) r c C s� | d k r | S| | j | d k rL t d d | | j | d f � � t | d | d d d d d | �} t | d d d | d d d d | �} t j | | | f d | �} | S) aB Create an ndarray that is 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 -------- >>> a = array([[1.0,2.0,3.0,4.0,5.0], [0.0, 1.0, 4.0, 9.0, 16.0]]) >>> _even_ext(a, 2) array([[ 3., 2., 1., 2., 3., 4., 5., 4., 3.], [ 4., 1., 0., 1., 4., 9., 16., 9., 4.]]) r z(The extension length n (%d) is too big. z0It must not exceed x.shape[axis]-1, which is %d.r r r r r r r r r )r r r r r )r r r r r r r r r �even_ext] s $) r! 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)a� Create an 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 -------- >>> a = array([[1.0,2.0,3.0,4.0,5.0], [0.0, 1.0, 4.0, 9.0, 16.0]]) >>> _const_ext(a, 2) array([[ 1., 1., 1., 2., 3., 4., 5., 5., 5.], [ 0., 0., 0., 1., 4., 9., 16., 16., 16.]]) r r r r r �dtyper )r r r �onesr"