Your IP : 216.73.216.213


Current Path : /opt/alt/python27/lib64/python2.7/site-packages/numpy/core/
Upload File :
Current File : //opt/alt/python27/lib64/python2.7/site-packages/numpy/core/shape_base.pyc

�
��]c@`s�ddlmZmZmZdddddddgZd	d
lmZd	dlmZm	Z	m
Z
d	dlmZd
�Z
d�Zd�Zd�Zd�Zdd�Zdefd��YZd�ZdS(i(tdivisiontabsolute_importtprint_functiont
atleast_1dt
atleast_2dt
atleast_3dtblockthstacktstacktvstacki(tnumeric(tarrayt
asanyarraytnewaxis(tnormalize_axis_indexcG`syg}xN|D]F}t|�}|jdkr@|jd�}n|}|j|�q
Wt|�dkrq|dS|SdS(s%
    Convert inputs to arrays with at least one dimension.

    Scalar inputs are converted to 1-dimensional arrays, whilst
    higher-dimensional inputs are preserved.

    Parameters
    ----------
    arys1, arys2, ... : array_like
        One or more input arrays.

    Returns
    -------
    ret : ndarray
        An array, or list of arrays, each with ``a.ndim >= 1``.
        Copies are made only if necessary.

    See Also
    --------
    atleast_2d, atleast_3d

    Examples
    --------
    >>> np.atleast_1d(1.0)
    array([ 1.])

    >>> x = np.arange(9.0).reshape(3,3)
    >>> np.atleast_1d(x)
    array([[ 0.,  1.,  2.],
           [ 3.,  4.,  5.],
           [ 6.,  7.,  8.]])
    >>> np.atleast_1d(x) is x
    True

    >>> np.atleast_1d(1, [3, 4])
    [array([1]), array([3, 4])]

    iiN(Rtndimtreshapetappendtlen(tarystrestarytresult((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/shape_base.pyRs'
cG`s�g}xy|D]q}t|�}|jdkrC|jdd�}n.|jdkrk|tdd�f}n|}|j|�q
Wt|�dkr�|dS|SdS(s`
    View inputs as arrays with at least two dimensions.

    Parameters
    ----------
    arys1, arys2, ... : array_like
        One or more array-like sequences.  Non-array inputs are converted
        to arrays.  Arrays that already have two or more dimensions are
        preserved.

    Returns
    -------
    res, res2, ... : ndarray
        An array, or list of arrays, each with ``a.ndim >= 2``.
        Copies are avoided where possible, and views with two or more
        dimensions are returned.

    See Also
    --------
    atleast_1d, atleast_3d

    Examples
    --------
    >>> np.atleast_2d(3.0)
    array([[ 3.]])

    >>> x = np.arange(3.0)
    >>> np.atleast_2d(x)
    array([[ 0.,  1.,  2.]])
    >>> np.atleast_2d(x).base is x
    True

    >>> np.atleast_2d(1, [1, 2], [[1, 2]])
    [array([[1]]), array([[1, 2]]), array([[1, 2]])]

    iiN(RRRR
RR(RRRR((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/shape_base.pyR?s%
cG`s�g}x�|D]�}t|�}|jdkrF|jddd�}nb|jdkrq|tdd�tf}n7|jdkr�|dd�dd�tf}n|}|j|�q
Wt|�dkr�|dS|SdS(s�
    View inputs as arrays with at least three dimensions.

    Parameters
    ----------
    arys1, arys2, ... : array_like
        One or more array-like sequences.  Non-array inputs are converted to
        arrays.  Arrays that already have three or more dimensions are
        preserved.

    Returns
    -------
    res1, res2, ... : ndarray
        An array, or list of arrays, each with ``a.ndim >= 3``.  Copies are
        avoided where possible, and views with three or more dimensions are
        returned.  For example, a 1-D array of shape ``(N,)`` becomes a view
        of shape ``(1, N, 1)``, and a 2-D array of shape ``(M, N)`` becomes a
        view of shape ``(M, N, 1)``.

    See Also
    --------
    atleast_1d, atleast_2d

    Examples
    --------
    >>> np.atleast_3d(3.0)
    array([[[ 3.]]])

    >>> x = np.arange(3.0)
    >>> np.atleast_3d(x).shape
    (1, 3, 1)

    >>> x = np.arange(12.0).reshape(4,3)
    >>> np.atleast_3d(x).shape
    (4, 3, 1)
    >>> np.atleast_3d(x).base is x.base  # x is a reshape, so not base itself
    True

    >>> for arr in np.atleast_3d([1, 2], [[1, 2]], [[[1, 2]]]):
    ...     print(arr, arr.shape)
    ...
    [[[1]
      [2]]] (1, 2, 1)
    [[[1]
      [2]]] (1, 2, 1)
    [[[1 2]]] (1, 1, 2)

    iiNi(RRRR
RR(RRRR((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/shape_base.pyRss1
"cC`s)tjg|D]}t|�^q
d�S(s
    Stack arrays in sequence vertically (row wise).

    Take a sequence of arrays and stack them vertically to make a single
    array. Rebuild arrays divided by `vsplit`.

    This function continues to be supported for backward compatibility, but
    you should prefer ``np.concatenate`` or ``np.stack``. The ``np.stack``
    function was added in NumPy 1.10.

    Parameters
    ----------
    tup : sequence of ndarrays
        Tuple containing arrays to be stacked. The arrays must have the same
        shape along all but the first axis.

    Returns
    -------
    stacked : ndarray
        The array formed by stacking the given arrays.

    See Also
    --------
    stack : Join a sequence of arrays along a new axis.
    hstack : Stack arrays in sequence horizontally (column wise).
    dstack : Stack arrays in sequence depth wise (along third dimension).
    concatenate : Join a sequence of arrays along an existing axis.
    vsplit : Split array into a list of multiple sub-arrays vertically.
    block : Assemble arrays from blocks.

    Notes
    -----
    Equivalent to ``np.concatenate(tup, axis=0)`` if `tup` contains arrays that
    are at least 2-dimensional.

    Examples
    --------
    >>> a = np.array([1, 2, 3])
    >>> b = np.array([2, 3, 4])
    >>> np.vstack((a,b))
    array([[1, 2, 3],
           [2, 3, 4]])

    >>> a = np.array([[1], [2], [3]])
    >>> b = np.array([[2], [3], [4]])
    >>> np.vstack((a,b))
    array([[1],
           [2],
           [3],
           [2],
           [3],
           [4]])

    i(t_nxtconcatenateR(ttupt_m((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/shape_base.pyR	�s7cC`s\g|D]}t|�^q}|rH|djdkrHtj|d�Stj|d�SdS(s�
    Stack arrays in sequence horizontally (column wise).

    Take a sequence of arrays and stack them horizontally to make
    a single array. Rebuild arrays divided by `hsplit`.

    This function continues to be supported for backward compatibility, but
    you should prefer ``np.concatenate`` or ``np.stack``. The ``np.stack``
    function was added in NumPy 1.10.

    Parameters
    ----------
    tup : sequence of ndarrays
        All arrays must have the same shape along all but the second axis.

    Returns
    -------
    stacked : ndarray
        The array formed by stacking the given arrays.

    See Also
    --------
    stack : Join a sequence of arrays along a new axis.
    vstack : Stack arrays in sequence vertically (row wise).
    dstack : Stack arrays in sequence depth wise (along third axis).
    concatenate : Join a sequence of arrays along an existing axis.
    hsplit : Split array along second axis.
    block : Assemble arrays from blocks.

    Notes
    -----
    Equivalent to ``np.concatenate(tup, axis=1)`` if `tup` contains arrays that
    are at least 2-dimensional.

    Examples
    --------
    >>> a = np.array((1,2,3))
    >>> b = np.array((2,3,4))
    >>> np.hstack((a,b))
    array([1, 2, 3, 2, 3, 4])
    >>> a = np.array([[1],[2],[3]])
    >>> b = np.array([[2],[3],[4]])
    >>> np.hstack((a,b))
    array([[1, 2],
           [2, 3],
           [3, 4]])

    iiN(RRRR(RRtarrs((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/shape_base.pyR�s1cC`s�g|D]}t|�^q}|s4td��ntd�|D��}t|�dkrktd��n|djd}t||�}td�f|tj	f}g|D]}||^q�}tj
|d|�S(s'
    Join a sequence of arrays along a new axis.

    The `axis` parameter specifies the index of the new axis in the dimensions
    of the result. For example, if ``axis=0`` it will be the first dimension
    and if ``axis=-1`` it will be the last dimension.

    .. versionadded:: 1.10.0

    Parameters
    ----------
    arrays : sequence of array_like
        Each array must have the same shape.
    axis : int, optional
        The axis in the result array along which the input arrays are stacked.

    Returns
    -------
    stacked : ndarray
        The stacked array has one more dimension than the input arrays.

    See Also
    --------
    concatenate : Join a sequence of arrays along an existing axis.
    split : Split array into a list of multiple sub-arrays of equal size.
    block : Assemble arrays from blocks.

    Examples
    --------
    >>> arrays = [np.random.randn(3, 4) for _ in range(10)]
    >>> np.stack(arrays, axis=0).shape
    (10, 3, 4)

    >>> np.stack(arrays, axis=1).shape
    (3, 10, 4)

    >>> np.stack(arrays, axis=2).shape
    (3, 4, 10)

    >>> a = np.array([1, 2, 3])
    >>> b = np.array([2, 3, 4])
    >>> np.stack((a, b))
    array([[1, 2, 3],
           [2, 3, 4]])

    >>> np.stack((a, b), axis=-1)
    array([[1, 2],
           [2, 3],
           [3, 4]])

    s need at least one array to stackcs`s|]}|jVqdS(N(tshape(t.0tarr((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/shape_base.pys	<genexpr>`sis)all input arrays must have the same shapeitaxisN(Rt
ValueErrortsetRRRtslicetNoneRR
R(tarraysRRtshapestresult_ndimtsltexpanded_arrays((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/shape_base.pyR(s4t	_RecursercB`s>eZdZd�Zd�d�d�d�Zdd�ZRS(s;
    Utility class for recursing over nested iterables
    cC`s
||_dS(N(t
recurse_if(tselfR*((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/shape_base.pyt__init__pscK`s|S(N((txtkwargs((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/shape_base.pyt<lambda>stcK`s|S(N((R-R.((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/shape_base.pyR/tR0cK`s|S(N((R.((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/shape_base.pyR/uR0c`s(�����fd���||�S(s{
        Iterate over the nested list, applying:
        * ``f_map`` (T -> U) to items
        * ``f_reduce`` (Iterable[U] -> U) to mapped items

        For instance, ``map_reduce([[1, 2], 3, 4])`` is::

            f_reduce([
              f_reduce([
                f_map(1),
                f_map(2)
              ]),
              f_map(3),
              f_map(4)
            ]])


        State can be passed down through the calls with `f_kwargs`,
        to iterables of mapped items. When kwargs are passed, as in
        ``map_reduce([[1, 2], 3, 4], **kw)``, this becomes::

            kw1 = f_kwargs(**kw)
            kw2 = f_kwargs(**kw1)
            f_reduce([
              f_reduce([
                f_map(1), **kw2)
                f_map(2,  **kw2)
              ],      **kw1),
              f_map(3, **kw1),
              f_map(4, **kw1)
            ]],     **kw)
        c`sL�j|�s�||�S�|�����fd�|D�|�SdS(Nc3`s|]}�|��VqdS(N((Rtxi(tftnext_kwargs(sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/shape_base.pys	<genexpr>�s(R*(R-R.(R2tf_kwargstf_maptf_reduceR+(R3sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/shape_base.pyR2�s
((R+R-R5R6R4R.((R2R4R5R6R+sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/shape_base.pyt
map_reducess$	cc`sq|j|�}|||fV|s'dSxCt|�D]5\}}x&|j|||f�D]}|VqZWq4WdS(sB
        Iterate over x, yielding (index, value, entering), where

        * ``index``: a tuple of indices up to this point
        * ``value``: equal to ``x[index[0]][...][index[-1]]``. On the first iteration, is
                     ``x`` itself
        * ``entering``: bool. The result of ``recurse_if(value)``
        N(R*t	enumeratetwalk(R+R-tindext
do_recursetiR1tv((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/shape_base.pyR9�s	 ((t__name__t
__module__t__doc__R,R7R9(((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/shape_base.pyR)ls	-c`s�d��d�}tdd��}d}t}x�|j|�D]�\}}}t|�tkrtdj||����n|s�t|�}n.t|�dkr@t|�d}t	}nq@|dk	r�||kr�t
dj||||����n|}q@W|rt
d	��n|j|d
tdt
�}|j|d
d�dt�}	t||	���|}
|j|d
��fd
�dt
�}|j|dd�dd�d|
�S(s9
    Assemble an nd-array from nested lists of blocks.

    Blocks in the innermost lists are concatenated (see `concatenate`) along
    the last dimension (-1), then these are concatenated along the
    second-last dimension (-2), and so on until the outermost list is reached.

    Blocks can be of any dimension, but will not be broadcasted using the normal
    rules. Instead, leading axes of size 1 are inserted, to make ``block.ndim``
    the same for all blocks. This is primarily useful for working with scalars,
    and means that code like ``np.block([v, 1])`` is valid, where
    ``v.ndim == 1``.

    When the nested list is two levels deep, this allows block matrices to be
    constructed from their components.

    .. versionadded:: 1.13.0

    Parameters
    ----------
    arrays : nested list of array_like or scalars (but not tuples)
        If passed a single ndarray or scalar (a nested list of depth 0), this
        is returned unmodified (and not copied).

        Elements shapes must match along the appropriate axes (without
        broadcasting), but leading 1s will be prepended to the shape as
        necessary to make the dimensions match.

    Returns
    -------
    block_array : ndarray
        The array assembled from the given blocks.

        The dimensionality of the output is equal to the greatest of:
        * the dimensionality of all the inputs
        * the depth to which the input list is nested

    Raises
    ------
    ValueError
        * If list depths are mismatched - for instance, ``[[a, b], c]`` is
          illegal, and should be spelt ``[[a, b], [c]]``
        * If lists are empty - for instance, ``[[a, b], []]``

    See Also
    --------
    concatenate : Join a sequence of arrays together.
    stack : Stack arrays in sequence along a new dimension.
    hstack : Stack arrays in sequence horizontally (column wise).
    vstack : Stack arrays in sequence vertically (row wise).
    dstack : Stack arrays in sequence depth wise (along third dimension).
    vsplit : Split array into a list of multiple sub-arrays vertically.

    Notes
    -----

    When called with only scalars, ``np.block`` is equivalent to an ndarray
    call. So ``np.block([[1, 2], [3, 4]])`` is equivalent to
    ``np.array([[1, 2], [3, 4]])``.

    This function does not enforce that the blocks lie on a fixed grid.
    ``np.block([[a, b], [c, d]])`` is not restricted to arrays of the form::

        AAAbb
        AAAbb
        cccDD

    But is also allowed to produce, for some ``a, b, c, d``::

        AAAbb
        AAAbb
        cDDDD

    Since concatenation happens along the last axis first, `block` is _not_
    capable of producing the following directly::

        AAAbb
        cccbb
        cccDD

    Matlab's "square bracket stacking", ``[A, B, ...; p, q, ...]``, is
    equivalent to ``np.block([[A, B, ...], [p, q, ...]])``.

    Examples
    --------
    The most common use of this function is to build a block matrix

    >>> A = np.eye(2) * 2
    >>> B = np.eye(3) * 3
    >>> np.block([
    ...     [A,               np.zeros((2, 3))],
    ...     [np.ones((3, 2)), B               ]
    ... ])
    array([[ 2.,  0.,  0.,  0.,  0.],
           [ 0.,  2.,  0.,  0.,  0.],
           [ 1.,  1.,  3.,  0.,  0.],
           [ 1.,  1.,  0.,  3.,  0.],
           [ 1.,  1.,  0.,  0.,  3.]])

    With a list of depth 1, `block` can be used as `hstack`

    >>> np.block([1, 2, 3])              # hstack([1, 2, 3])
    array([1, 2, 3])

    >>> a = np.array([1, 2, 3])
    >>> b = np.array([2, 3, 4])
    >>> np.block([a, b, 10])             # hstack([a, b, 10])
    array([1, 2, 3, 2, 3, 4, 10])

    >>> A = np.ones((2, 2), int)
    >>> B = 2 * A
    >>> np.block([A, B])                 # hstack([A, B])
    array([[1, 1, 2, 2],
           [1, 1, 2, 2]])

    With a list of depth 2, `block` can be used in place of `vstack`:

    >>> a = np.array([1, 2, 3])
    >>> b = np.array([2, 3, 4])
    >>> np.block([[a], [b]])             # vstack([a, b])
    array([[1, 2, 3],
           [2, 3, 4]])

    >>> A = np.ones((2, 2), int)
    >>> B = 2 * A
    >>> np.block([[A], [B]])             # vstack([A, B])
    array([[1, 1],
           [1, 1],
           [2, 2],
           [2, 2]])

    It can also be used in places of `atleast_1d` and `atleast_2d`

    >>> a = np.array(0)
    >>> b = np.array([1])
    >>> np.block([a])                    # atleast_1d(a)
    array([0])
    >>> np.block([b])                    # atleast_1d(b)
    array([1])

    >>> np.block([[a]])                  # atleast_2d(a)
    array([[0]])
    >>> np.block([[b]])                  # atleast_2d(b)
    array([[1]])


    cS`s5t|�}t||jd�}|d|tfS(Ni(N(RtmaxRR#tEllipsis(R-Rtdiff((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/shape_base.pyt
atleast_ndJscS`sddjd�|D��S(NR$R0cs`s|]}dj|�VqdS(s[{}]N(tformat(RR<((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/shape_base.pys	<genexpr>Ps(tjoin(R:((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/shape_base.pytformat_indexOsR*cS`st|�tkS(N(ttypetlist(R-((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/shape_base.pyR/RR0s{} is a tuple. Only lists can be used to arrange blocks, and np.block does not allow implicit conversion from tuple to ndarray.iiscList depths are mismatched. First element was at depth {}, but there is an element at depth {} ({})sLists cannot be emptyR5R6cS`s|jS(N(R(R1((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/shape_base.pyR/�R0c`s
�|��S(N((R1(RDR(sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/shape_base.pyR/�R0cS`stjt|�d|�S(NR(RRRI(txsR((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/shape_base.pyR/�R0R4cS`std|d�S(NRi(tdict(R((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/shape_base.pyR/�R0RN(R)R#tFalseR9RHttuplet	TypeErrorRERtTrueR R7RRIRA(R$RGtrect	list_ndimt	any_emptyR:tvaluetenteringt
curr_deptht	elem_ndimt
first_axis((RDRsH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/shape_base.pyR�sP�			
			
			N(t
__future__RRRt__all__R0R
RRRR
t
multiarrayRRRRR	RRtobjectR)R(((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/shape_base.pyt<module>s	4	4	C	9	9DJ