Current File : //usr/lib64/python2.7/site-packages/numpy/ma/extras.pyo
�
E�`Qc*@s\dZdZdZdZdZddddd	d
ddd
ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.g*Zd/d0lZd/d0lZd/d0lZ	d/d1lm
Z
mZmZm
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZd/d0lZd/d2lmZm
Zd/d0l jj!Z!d/d3l"m#Z#d/d4l$m%Z%d5�Z&d0d6�Z(e)d7�Z*d8�Z+d9d^d:��YZ,e,d�Z-e,d�Z.e,d	�Z/e,d.�Z0Z1e,d�Z2e,d
�Z3e,d�Z4e,d�Z5e,d�Z6d;�Z7d<�Z8ej8je8_d=�Z9ej9je9_d0d0e:d>�Z;d0d0e:d?�Z<d0d@�Z=dA�Z>dB�Z?d0dC�Z@d0dD�ZAd0dE�ZBe:dF�ZCd0d0dG�ZDe:e:dH�ZEe:dI�ZFe:dJ�ZGe:dK�ZHdL�ZIe:dM�ZJd0eKeKdN�ZLd0eKe:eKd0dO�ZMd0eKe:eKd0dP�ZNdQe#fdR��YZOdSeOfdT��YZPeP�ZQdU�ZRd0dV�ZSdW�ZTd0dX�ZUdY�ZVdZ�ZWd[�ZXd0d\�ZYe	jZejYjeYj�eY_d0e:d0e:d]�Z[e	jZej[je[j�e[_d0S(_s�
Masked arrays add-ons.

A collection of utilities for `numpy.ma`.

:author: Pierre Gerard-Marchant
:contact: pierregm_at_uga_dot_edu
:version: $Id: extras.py 3473 2007-10-29 15:18:13Z jarrod.millman $

s5Pierre GF Gerard-Marchant ($Author: jarrod.millman $)s1.0s$Revision: 3473 $s5$Date: 2007-10-29 17:18:13 +0200 (Mon, 29 Oct 2007) $tapply_along_axistapply_over_axest
atleast_1dt
atleast_2dt
atleast_3dtaveragetclump_maskedtclump_unmaskedtcolumn_stackt
compress_colstcompress_rowcolst
compress_rowstcount_maskedtcorrcoeftcovtdiagflattdottdstacktediff1dtflatnotmasked_contiguoustflatnotmasked_edgesthsplitthstacktin1dtintersect1dt	mask_colstmask_rowcolst	mask_rowst
masked_alltmasked_all_liketmediantmr_tnotmasked_contiguoustnotmasked_edgestpolyfitt	row_stackt	setdiff1dtsetxor1dtuniquetunion1dtvandertvstacki����N(tMaskedArraytMAErrortaddtarraytasarraytconcatenatetcounttfilledtgetmasktgetmaskarraytmake_mask_descrtmaskedtmasked_arraytmask_ortnomasktonestsorttzeros(tndarrayR-(tAxisConcatenator(tlstsqcCs t|tttf�rtStS(s+Is seq a sequence (ndarray, list or tuple)?(t
isinstanceR<ttupletlisttTruetFalse(tseq((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyt
issequence5scCst|�}|j|�S(s�
    Count the number of masked elements along the given axis.

    Parameters
    ----------
    arr : array_like
        An array with (possibly) masked elements.
    axis : int, optional
        Axis along which to count. If None (default), a flattened
        version of the array is used.

    Returns
    -------
    count : int, ndarray
        The total number of masked elements (axis=None) or the number
        of masked elements along each slice of the given axis.

    See Also
    --------
    MaskedArray.count : Count non-masked elements.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> a = np.arange(9).reshape((3,3))
    >>> a = ma.array(a)
    >>> a[1, 0] = ma.masked
    >>> a[1, 2] = ma.masked
    >>> a[2, 1] = ma.masked
    >>> a
    masked_array(data =
     [[0 1 2]
     [-- 4 --]
     [6 -- 8]],
          mask =
     [[False False False]
     [ True False  True]
     [False  True False]],
          fill_value=999999)
    >>> ma.count_masked(a)
    3

    When the `axis` keyword is used an array is returned.

    >>> ma.count_masked(a, axis=0)
    array([1, 1, 1])
    >>> ma.count_masked(a, axis=1)
    array([0, 2, 1])

    (R3tsum(tarrtaxistm((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyR;s3cCs4ttj||�dtj|t|���}|S(s�
    Empty masked array with all elements masked.

    Return an empty masked array of the given shape and dtype, where all the
    data are masked.

    Parameters
    ----------
    shape : tuple
        Shape of the required MaskedArray.
    dtype : dtype, optional
        Data type of the output.

    Returns
    -------
    a : MaskedArray
        A masked array with all data masked.

    See Also
    --------
    masked_all_like : Empty masked array modelled on an existing array.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> ma.masked_all((3, 3))
    masked_array(data =
     [[-- -- --]
     [-- -- --]
     [-- -- --]],
          mask =
     [[ True  True  True]
     [ True  True  True]
     [ True  True  True]],
          fill_value=1e+20)

    The `dtype` parameter defines the underlying data type.

    >>> a = ma.masked_all((3, 3))
    >>> a.dtype
    dtype('float64')
    >>> a = ma.masked_all((3, 3), dtype=np.int32)
    >>> a.dtype
    dtype('int32')

    tmask(R6tnptemptyR9R4(tshapetdtypeta((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyRqs/cCs@tj|�jt�}tj|jdt|j��|_|S(sz
    Empty masked array with the properties of an existing array.

    Return an empty masked array of the same shape and dtype as
    the array `arr`, where all the data are masked.

    Parameters
    ----------
    arr : ndarray
        An array describing the shape and dtype of the required MaskedArray.

    Returns
    -------
    a : MaskedArray
        A masked array with all data masked.

    Raises
    ------
    AttributeError
        If `arr` doesn't have a shape attribute (i.e. not an ndarray)

    See Also
    --------
    masked_all : Empty masked array with all elements masked.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> arr = np.zeros((2, 3), dtype=np.float32)
    >>> arr
    array([[ 0.,  0.,  0.],
           [ 0.,  0.,  0.]], dtype=float32)
    >>> ma.masked_all_like(arr)
    masked_array(data =
     [[-- -- --]
     [-- -- --]],
          mask =
     [[ True  True  True]
     [ True  True  True]],
          fill_value=1e+20)

    The dtype of the masked array matches the dtype of `arr`.

    >>> arr.dtype
    dtype('float32')
    >>> ma.masked_all_like(arr).dtype
    dtype('float32')

    RN(	RKt
empty_liketviewR*R9RMR4RNt_mask(RGRO((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyR�s2$t_fromnxfunctioncBs)eZdZd�Zd�Zd�ZRS(s�
    Defines a wrapper to adapt NumPy functions to masked arrays.


    An instance of `_fromnxfunction` can be called with the same parameters
    as the wrapped NumPy function. The docstring of `newfunc` is adapted from
    the wrapped function as well, see `getdoc`.

    Parameters
    ----------
    funcname : str
        The name of the function to be adapted. The function should be
        in the NumPy namespace (i.e. ``np.funcname``).

    cCs||_|j�|_dS(N(t__name__tgetdoct__doc__(tselftfuncname((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyt__init__�s	cCsctt|jd�}t|dd�}|r_|jtj|�}d}dj|||f�SdS(s 
        Retrieve the docstring and signature from the function.

        The ``__doc__`` attribute of the function is used as the docstring for
        the new masked array version of the function. A note on application
        of the function to the mask is appended.

        .. warning::
          If the function docstring already contained a Notes section, the
          new docstring will have two Notes sections instead of appending a note
          to the existing section.

        Parameters
        ----------
        None

        RVsLNotes
-----
The function is applied to both the _data and the _mask, if any.s
N(tgetattrRKRTtNonetmatget_object_signaturetjoin(RWtnpfunctdoctsigtlocdoc((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyRU�sc
Os�tt|j�}t|�dkr|d}t|t�rw||j�|�}|t|�|�}t|d|�St|t	�s�t|t
�r�|t	g|D]}tj|�^q��|�}|t	g|D]}t|�^q��|�}t|d|�Sn�g}t
|�}x<t|�dkrWt|d�rW|j
|jd��qWg}	xZ|D]R}|tj|�||�}|t|�||�}|	j
t|d|��qeW|	SdS(NiiRJ(RZRKRTtlenR?R<t	__array__R3R6R@RAR.REtappendtpop(
RWtargstparamstfunctxt_dt_mROtarraystres((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyt__call__s*
1.%
(RTt
__module__RVRYRURo(((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyRS�s		cCs\d}xO|t|�krWx,t||d�rI|||||d+qW|d7}q	W|S(sFlatten a sequence in place.it__iter__i(Rcthasattr(RDtk((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pytflatten_inplace;scOs�t|dtdt�}|j}|dkr:||7}n||kr_td||f��ndg|d}tj|d�}t|�}|j|�t	d
d
�||<tj|j�j
|�}	|j||�|j�}
||t|j��||�}tj|�}|sGyt|�WqGtk
rCt}qGXng}
|r�|
jtj|�j�t|	t�}||t|�<tj|	�}d}x�||kr}|dcd7<d}xP|||	|kr|d|kr||dcd7<d||<|d8}q�W|j||�||t|j��||�}||t|�<|
jt|�j�|d7}q�Wn�t|dtdt�}|j�}
t	d
d
�g|j|
|<|
j||�tj|	�}|	}t|j�}	|j|	|<|
jt|�j�t|	�}	t|	t�}||tt|
j���<d}x�||krO|dcd7<d}xP||||kr�|d|kr�||dcd7<d||<|d8}q~W|j||�|
j||�||t|j��||�}||tt|
j���<|
jt|�j�|d7}qYWtjtj|
�j��}t|d�s�tj|d	|�}n$t|d	|�}tj|�|_|S(s0
    (This docstring should be overwritten)
    tcopytsubokis2axis must be less than arr.ndim; axis=%d, rank=%d.itOi����RRRNN( R-RCRBtndimt
ValueErrorRKR;trangetremovetsliceR[R.RMttaketputRuR@ttolisttisscalarRct	TypeErrorReRNtobjecttproductRARttmaxRrR\tdefault_fill_valuet
fill_value(tfunc1dRHRGRgtkwargstndtindtitindlisttoutshapetjRntasscalartdtypestoutarrtNtotRstnt	holdshapet
max_dtypestresult((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyREs�	

"

'
"
'
"c	Cstj|�}t|�}|j}t|�jdkrE|f}nx�|D]�}|dkrk||}n||f}tj|||f�d|||f��}|j|jkr�|j|j}}qLtj||�}|j|jkr|j|j}}qLt	d��qLW|S(s.
    (This docstring will be overwritten)
    iRJs3Function is not returning an array of correct shape(
RKR.R3RxR-R\t_dataRRtexpand_dimsRy(	RiROtaxestvaltmsktNRHRgRn((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyR�s"	

-c
	CsQt|�}|j}|j}|dkr3d}n|d
krb|tkr�|d
kr{|jdd
�}t|j�}q_t|d�j	�}t
jj|j
j	�|�}t
jj|�}~qW|d
kr|jd�jdd
�}tt
jj|j	���}qWtt|d�td|�j	�}tj|j	�|�}tj|�}~n�|tkr�|d
kr�||d}tj|j
|dt�}qWt|d�}|j}	|	dkr�d}	n|	|kr%tj|tdd�}tj|||�}tj||�}~qW|	||fkr�||}
d
gt|�}td
d
d�||<td	tt|��d
�}tj|||dt�}tj||dt�}~~qWtd��n�|d
krtj||dt�}t
jj|d|dt�}n:t|d�}|j}	|	dkrJd}	n|	|kr�t|dtd|dd�}tj|||dt�}tj||dt�}n�|	||fkrH||}
d
gt|�}td
d
d�||<td	tt|��d�}tj|||dt�}tj||dt�}ntd��~|tkso|tkrstS||}~t|t�r9|d
ks�|dkr�|jdkr�|jtkr�|j
}n|r9t|t�s�t|�}nt|t�r6|j|jkr6t|jdt�|}q6q9n|rI||fS|Sd
S(s(
    Return the weighted average of array over the given axis.

    Parameters
    ----------
    a : array_like
        Data to be averaged.
        Masked entries are not taken into account in the computation.
    axis : int, optional
        Axis along which the variance is computed. The default is to compute
        the variance of the flattened array.
    weights : array_like, optional
        The importance that each element has in the computation of the average.
        The weights array can either be 1-D (in which case its length must be
        the size of `a` along the given axis) or of the same shape as `a`.
        If ``weights=None``, then all data in `a` are assumed to have a
        weight equal to one.
    returned : bool, optional
        Flag indicating whether a tuple ``(result, sum of weights)``
        should be returned as output (True), or just the result (False).
        Default is False.

    Returns
    -------
    average, [sum_of_weights] : (tuple of) scalar or MaskedArray
        The average along the specified axis. When returned is `True`,
        return a tuple with the average as the first element and the sum
        of the weights as the second element. The return type is `np.float64`
        if `a` is of integer type, otherwise it is of the same type as `a`.
        If returned, `sum_of_weights` is of the same type as `average`.

    Examples
    --------
    >>> a = np.ma.array([1., 2., 3., 4.], mask=[False, False, True, True])
    >>> np.ma.average(a, weights=[3, 1, 0, 0])
    1.25

    >>> x = np.ma.arange(6.).reshape(3, 2)
    >>> print x
    [[ 0.  1.]
     [ 2.  3.]
     [ 4.  5.]]
    >>> avg, sumweights = np.ma.average(x, axis=0, weights=[1, 2, 3],
    ...                                 returned=True)
    >>> print avg
    [2.66666666667 3.66666666667]

    iRHgiRJg�?RNRusw[s] * ones(ash, float)saverage: weights wrong shape.s(] * masked_array(ones(ash, float), mask)N((i((i((i(R.RJRMR[R8RFtfloattsizeR1traveltumathR,treduceR�R-RKRcR|tevaltreprR@RyR5R?R*RxR6R<R9(
RORHtweightstreturnedRJtashR�tdtwtwshtnitrR�((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyR�s�1			"$		
 	"		


'""
cCs�d�}|rM|dkr4|j�}|j�q_|jd|�|}nt|d|�}|dkrz||�}nt|||�}|dk	r�|}n|S(sA
    Compute the median along the specified axis.

    Returns the median of the array elements.

    Parameters
    ----------
    a : array_like
        Input array or object that can be converted to an array.
    axis : int, optional
        Axis along which the medians are computed. The default (None) is
        to compute the median along a flattened version of the array.
    out : ndarray, optional
        Alternative output array in which to place the result. It must
        have the same shape and buffer length as the expected output
        but the type will be cast if necessary.
    overwrite_input : bool, optional
        If True, then allow use of memory of input array (a) for
        calculations. The input array will be modified by the call to
        median. This will save memory when you do not need to preserve
        the contents of the input array. Treat the input as undefined,
        but it will probably be fully or partially sorted. Default is
        False. Note that, if `overwrite_input` is True, and the input
        is not already an `ndarray`, an error will be raised.

    Returns
    -------
    median : ndarray
        A new array holding the result is returned unless out is
        specified, in which case a reference to out is returned.
        Return data-type is `float64` for integers and floats smaller than
        `float64`, or the input data-type, otherwise.

    See Also
    --------
    mean

    Notes
    -----
    Given a vector ``V`` with ``N`` non masked values, the median of ``V``
    is the middle value of a sorted copy of ``V`` (``Vs``) - i.e.
    ``Vs[(N-1)/2]``, when ``N`` is odd, or ``{Vs[N/2 - 1] + Vs[N/2]}/2``
    when ``N`` is even.

    Examples
    --------
    >>> x = np.ma.array(np.arange(8), mask=[0]*4 + [1]*4)
    >>> np.ma.extras.median(x)
    1.5

    >>> x = np.ma.array(np.arange(10).reshape(2, 5), mask=[0]*6 + [1]*4)
    >>> np.ma.extras.median(x)
    2.5
    >>> np.ma.extras.median(x, axis=-1, overwrite_input=True)
    masked_array(data = [ 2.  5.],
                 mask = False,
           fill_value = 1e+20)

    cSsntt|�d�}t|d�\}}|rFt||d�}nt|d|d�}||jd�S(Niii(R1R0tdivmodR|tmean(tdatatcountstidxtrmdtchoice((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyt	_median1D�sRHN(R[R�R:R(RORHtouttoverwrite_inputR�tasortedR�((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyRFs<		
		cCs't|�}|jdkr*td��nt|�}|tksO|j�rV|jS|j�rltg�St	t
|��t	|jd�}}|j�}|s�x+t
j|d�D]}|j|�q�Wn|dkrx+t
j|d�D]}|j|�q�Wn|j|dd�|fS(s�
    Suppress the rows and/or columns of a 2-D array that contain
    masked values.

    The suppression behavior is selected with the `axis` parameter.

    - If axis is None, both rows and columns are suppressed.
    - If axis is 0, only rows are suppressed.
    - If axis is 1 or -1, only columns are suppressed.

    Parameters
    ----------
    axis : int, optional
        Axis along which to perform the operation. Default is None.

    Returns
    -------
    compressed_array : ndarray
        The compressed array.

    Examples
    --------
    >>> x = np.ma.array(np.arange(9).reshape(3, 3), mask=[[1, 0, 0],
    ...                                                   [1, 0, 0],
    ...                                                   [0, 0, 0]])
    >>> x
    masked_array(data =
     [[-- 1 2]
     [-- 4 5]
     [6 7 8]],
                 mask =
     [[ True False False]
     [ True False False]
     [False False False]],
           fill_value = 999999)

    >>> np.ma.extras.compress_rowcols(x)
    array([[7, 8]])
    >>> np.ma.extras.compress_rowcols(x, 0)
    array([[6, 7, 8]])
    >>> np.ma.extras.compress_rowcols(x, 1)
    array([[1, 2],
           [4, 5],
           [7, 8]])

    is$compress2d works for 2D arrays only.iii����N(Nii����(R.RxtNotImplementedErrorR2R8tanyR�talltnxarrayRzRcRMtnonzeroRKR&R{R[(RjRHRItidxrtidxcR5R�R�((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyR
�s"/
&cCs
t|d�S(s�
    Suppress whole rows of a 2-D array that contain masked values.

    This is equivalent to ``np.ma.extras.compress_rowcols(a, 0)``, see
    `extras.compress_rowcols` for details.

    See Also
    --------
    extras.compress_rowcols

    i(R
(RO((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyR�scCs
t|d�S(s�
    Suppress whole columns of a 2-D array that contain masked values.

    This is equivalent to ``np.ma.extras.compress_rowcols(a, 1)``, see
    `extras.compress_rowcols` for details.

    See Also
    --------
    extras.compress_rowcols

    i(R
(RO((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyR	�scCs�t|�}|jdkr*td��nt|�}|tksO|j�rS|S|j�}|jj�|_|s�t	|t
j|d�<n|dkr�t	|dd�t
j|d�f<n|S(s�
    Mask rows and/or columns of a 2D array that contain masked values.

    Mask whole rows and/or columns of a 2D array that contain
    masked values.  The masking behavior is selected using the
    `axis` parameter.

      - If `axis` is None, rows *and* columns are masked.
      - If `axis` is 0, only rows are masked.
      - If `axis` is 1 or -1, only columns are masked.

    Parameters
    ----------
    a : array_like, MaskedArray
        The array to mask.  If not a MaskedArray instance (or if no array
        elements are masked).  The result is a MaskedArray with `mask` set
        to `nomask` (False). Must be a 2D array.
    axis : int, optional
        Axis along which to perform the operation. If None, applies to a
        flattened version of the array.

    Returns
    -------
    a : MaskedArray
        A modified version of the input array, masked depending on the value
        of the `axis` parameter.

    Raises
    ------
    NotImplementedError
        If input array `a` is not 2D.

    See Also
    --------
    mask_rows : Mask rows of a 2D array that contain masked values.
    mask_cols : Mask cols of a 2D array that contain masked values.
    masked_where : Mask where a condition is met.

    Notes
    -----
    The input array's mask is modified by this function.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> a = np.zeros((3, 3), dtype=np.int)
    >>> a[1, 1] = 1
    >>> a
    array([[0, 0, 0],
           [0, 1, 0],
           [0, 0, 0]])
    >>> a = ma.masked_equal(a, 1)
    >>> a
    masked_array(data =
     [[0 0 0]
     [0 -- 0]
     [0 0 0]],
          mask =
     [[False False False]
     [False  True False]
     [False False False]],
          fill_value=999999)
    >>> ma.mask_rowcols(a)
    masked_array(data =
     [[0 -- 0]
     [-- -- --]
     [0 -- 0]],
          mask =
     [[False  True False]
     [ True  True  True]
     [False  True False]],
          fill_value=999999)

    is$compress2d works for 2D arrays only.iii����N(Nii����(
R.RxR�R2R8R�R�RRRuR5RKR&R[(RORHRIt	maskedval((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyRsK&cCs
t|d�S(s�
    Mask rows of a 2D array that contain masked values.

    This function is a shortcut to ``mask_rowcols`` with `axis` equal to 0.

    See Also
    --------
    mask_rowcols : Mask rows and/or columns of a 2D array.
    masked_where : Mask where a condition is met.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> a = np.zeros((3, 3), dtype=np.int)
    >>> a[1, 1] = 1
    >>> a
    array([[0, 0, 0],
           [0, 1, 0],
           [0, 0, 0]])
    >>> a = ma.masked_equal(a, 1)
    >>> a
    masked_array(data =
     [[0 0 0]
     [0 -- 0]
     [0 0 0]],
          mask =
     [[False False False]
     [False  True False]
     [False False False]],
          fill_value=999999)
    >>> ma.mask_rows(a)
    masked_array(data =
     [[0 0 0]
     [-- -- --]
     [0 0 0]],
          mask =
     [[False False False]
     [ True  True  True]
     [False False False]],
          fill_value=999999)

    i(R(RORH((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyRZs+cCs
t|d�S(s�
    Mask columns of a 2D array that contain masked values.

    This function is a shortcut to ``mask_rowcols`` with `axis` equal to 1.

    See Also
    --------
    mask_rowcols : Mask rows and/or columns of a 2D array.
    masked_where : Mask where a condition is met.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> a = np.zeros((3, 3), dtype=np.int)
    >>> a[1, 1] = 1
    >>> a
    array([[0, 0, 0],
           [0, 1, 0],
           [0, 0, 0]])
    >>> a = ma.masked_equal(a, 1)
    >>> a
    masked_array(data =
     [[0 0 0]
     [0 -- 0]
     [0 0 0]],
          mask =
     [[False False False]
     [False  True False]
     [False False False]],
          fill_value=999999)
    >>> ma.mask_cols(a)
    masked_array(data =
     [[0 -- 0]
     [0 -- 0]
     [0 -- 0]],
          mask =
     [[False  True False]
     [False  True False]
     [False  True False]],
          fill_value=999999)

    i(R(RORH((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyR�s+cCs�|r?|jdkr?|jdkr?t|�}t|�}ntjt|d�t|d��}t|�}t|�}tj||�}t|d|�S(s�
    Return the dot product of two arrays.

    .. note::
      Works only with 2-D arrays at the moment.

    This function is the equivalent of `numpy.dot` that takes masked values
    into account, see `numpy.dot` for details.

    Parameters
    ----------
    a, b : ndarray
        Inputs arrays.
    strict : bool, optional
        Whether masked data are propagated (True) or set to 0 (False) for the
        computation. Default is False.
        Propagating the mask means that if a masked value appears in a row or
        column, the whole row or column is considered masked.

    See Also
    --------
    numpy.dot : Equivalent function for ndarrays.

    Examples
    --------
    >>> a = ma.array([[1, 2, 3], [4, 5, 6]], mask=[[1, 0, 0], [0, 0, 0]])
    >>> b = ma.array([[1, 2], [3, 4], [5, 6]], mask=[[1, 0], [0, 0], [0, 0]])
    >>> np.ma.dot(a, b)
    masked_array(data =
     [[21 26]
     [45 64]],
                 mask =
     [[False False]
     [False False]],
           fill_value = 999999)
    >>> np.ma.dot(a, b, strict=True)
    masked_array(data =
     [[-- --]
     [-- 64]],
                 mask =
     [[ True  True]
     [ True False]],
           fill_value = 999999)

    iiRJ(RxRRRKRR1R3R6(ROtbtstrictR�tamtbmRI((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyR�s/$$

cCs�tj|�j}|d|d }|g}|dk	rL|jd|�n|dk	rh|j|�nt|�dkr�t|�}n|S(s!
    Compute the differences between consecutive elements of an array.

    This function is the equivalent of `numpy.ediff1d` that takes masked
    values into account, see `numpy.ediff1d` for details.

    See Also
    --------
    numpy.ediff1d : Equivalent function for ndarrays.

    ii����iN(R\t
asanyarraytflatR[tinsertReRcR(RGtto_endtto_begintedRm((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyR�s	cCsotj|d|d|�}t|t�r\t|�}|djt�|d<t|�}n|jt�}|S(s
    Finds the unique elements of an array.

    Masked values are considered the same element (masked). The output array
    is always a masked array. See `numpy.unique` for more details.

    See Also
    --------
    numpy.unique : Equivalent function for ndarrays.

    treturn_indextreturn_inversei(RKR&R?R@RARQR*(tar1R�R�toutput((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyR&s	cCsc|rtj||f�}n!tjt|�t|�f�}|j�|d |d|d kS(s.
    Returns the unique elements common to both arrays.

    Masked values are considered equal one to the other.
    The output is always a masked array.

    See `numpy.intersect1d` for more details.

    See Also
    --------
    numpy.intersect1d : Equivalent function for ndarrays.

    Examples
    --------
    >>> x = array([1, 3, 3, 3], mask=[0, 0, 0, 1])
    >>> y = array([3, 1, 1, 1], mask=[0, 0, 0, 1])
    >>> intersect1d(x, y)
    masked_array(data = [1 3 --],
                 mask = [False False  True],
           fill_value = 999999)

    i����i(R\R/R&R:(R�tar2t
assume_uniquetaux((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyR(s
!
cCs�|s!t|�}t|�}ntj||f�}|jdkrI|S|j�|j�}tjtg|d|d ktgf�}|d|d k}||S(s�
    Set exclusive-or of 1-D arrays with unique elements.

    The output is always a masked array. See `numpy.setxor1d` for more details.

    See Also
    --------
    numpy.setxor1d : Equivalent function for ndarrays.

    iii����(R&R\R/R�R:R1RB(R�R�R�R�tauxftflagtflag2((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyR%Hs
,c
Cs�|s-t|dt�\}}t|�}ntj||f�}|jdd�}||}|d|d k}tj|tgf�}|jdd�t|� }	|r�||	S||	|SdS(s#
    Test whether each element of an array is also present in a second
    array.

    The output is always a masked array. See `numpy.in1d` for more details.

    See Also
    --------
    numpy.in1d : Equivalent function for ndarrays.

    Notes
    -----
    .. versionadded:: 1.4.0

    R�tkindt	mergesortii����N(R&RBR\R/targsortRCRc(
R�R�R�trev_idxtartordertsart	equal_adjR�tindx((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyRbs
cCsttj||f��S(s�
    Union of two arrays.

    The output is always a masked array. See `numpy.union1d` for more details.

    See also
    --------
    numpy.union1d : Equivalent function for ndarrays.

    (R&R\R/(R�R�((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyR'�scCsd|s!t|�}t|�}nt||dt�}|jdkrI|Stj|�|dkSdS(s�
    Set difference of 1D arrays with unique elements.

    The output is always a masked array. See `numpy.setdiff1d` for more
    details.

    See Also
    --------
    numpy.setdiff1d : Equivalent function for ndarrays.

    Examples
    --------
    >>> x = np.ma.array([1, 2, 3, 4], mask=[0, 1, 0, 1])
    >>> np.ma.extras.setdiff1d(x, [1, 2])
    masked_array(data = [3 --],
                 mask = [False  True],
           fill_value = 999999)

    R�iN(R&RRBR�R\R.(R�R�R�R�((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyR$�sc
	Cstj|dddtdt�}tj|�}|rR|j�rRtd��n|jddkrnt}ntt	|��}d|}|r�t
d	�d	f}nd	t
d	�f}|d	kr�tj
|�jt�}nt|dtdddt�}tj|�}|r-|j�r-td��n|j�sE|j�r�|j|jkr�tj||�}	|	tk	r�|j�|j�|	}|_|_}q�q�ntj||f|�}tj
tj||f|��jt�}||jd|�|8}|||fS(
s_
    Private function for the computation of covariance and correlation
    coefficients.

    tndminiRuRNsCannot process masked data...iiRHN(R\R-RBR�R3R�RyRMtinttboolR|R[RKtlogical_nottastypeRCt
logical_orR8tunshare_maskRRR/R�(
Rjtytrowvartallow_maskedtxmaskRHttuptxnotmasktymasktcommon_mask((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyt
_covhelper�s8!	


!*c	Cs|dk	r-|t|�kr-td��n|dkrQ|rHd}qQd}nt||||�\}}}|s�tj|j|�d|}t|j|j�dt�|j	�}nEtj||j�d|}t||jj�dt�|j	�}|S(sK
    Estimate the covariance matrix.

    Except for the handling of missing data this function does the same as
    `numpy.cov`. For more details and examples, see `numpy.cov`.

    By default, masked values are recognized as such. If `x` and `y` have the
    same shape, a common mask is allocated: if ``x[i,j]`` is masked, then
    ``y[i,j]`` will also be masked.
    Setting `allow_masked` to False will raise an exception if values are
    missing in either of the input arrays.

    Parameters
    ----------
    x : array_like
        A 1-D or 2-D array containing multiple variables and observations.
        Each row of `x` represents a variable, and each column a single
        observation of all those variables. Also see `rowvar` below.
    y : array_like, optional
        An additional set of variables and observations. `y` has the same
        form as `x`.
    rowvar : bool, optional
        If `rowvar` is True (default), then each row represents a
        variable, with observations in the columns. Otherwise, the relationship
        is transposed: each column represents a variable, while the rows
        contain observations.
    bias : bool, optional
        Default normalization (False) is by ``(N-1)``, where ``N`` is the
        number of observations given (unbiased estimate). If `bias` is True,
        then normalization is by ``N``. This keyword can be overridden by
        the keyword ``ddof`` in numpy versions >= 1.5.
    allow_masked : bool, optional
        If True, masked values are propagated pair-wise: if a value is masked
        in `x`, the corresponding value is masked in `y`.
        If False, raises a `ValueError` exception when some values are missing.
    ddof : {None, int}, optional
        .. versionadded:: 1.5
        If not ``None`` normalization is by ``(N - ddof)``, where ``N`` is
        the number of observations; this overrides the value implied by
        ``bias``. The default value is ``None``.


    Raises
    ------
    ValueError:
        Raised if some values are missing and `allow_masked` is False.

    See Also
    --------
    numpy.cov

    sddof must be an integeriig�?R�N(
R[R�RyR�RKRtTtconjRCtsqueeze(	RjR�R�tbiasR�tddofR�tfactR�((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyR�s6		+(c	Cs�|dk	r-|t|�kr-td��n|dkrQ|rHd}qQd}nt||||�\}}}|s�tj|j|�d|}t|j|j�dt�|j	�}nEtj||j�d|}t||jj�dt�|j	�}yt
j|�}	Wntk
r)dSX|j�rWt
j
t
jj|	|	��}
n�t|	�}
|jd|}|rx\t|d�D]�}x�t|d|�D]o}
tt||||
f��jdddd|�}t
j
t
jj|��|
||
f<|
|
|f<q�Wq�Wn�x�t|d�D]�}x�t|d|�D]�}
tt|dd�|f|dd�|
ff��jdddd|�}t
j
t
jj|��|
||
f<|
|
|f<qJWq0W||
S(	s�
    Return correlation coefficients of the input array.

    Except for the handling of missing data this function does the same as
    `numpy.corrcoef`. For more details and examples, see `numpy.corrcoef`.

    Parameters
    ----------
    x : array_like
        A 1-D or 2-D array containing multiple variables and observations.
        Each row of `x` represents a variable, and each column a single
        observation of all those variables. Also see `rowvar` below.
    y : array_like, optional
        An additional set of variables and observations. `y` has the same
        shape as `x`.
    rowvar : bool, optional
        If `rowvar` is True (default), then each row represents a
        variable, with observations in the columns. Otherwise, the relationship
        is transposed: each column represents a variable, while the rows
        contain observations.
    bias : bool, optional
        Default normalization (False) is by ``(N-1)``, where ``N`` is the
        number of observations given (unbiased estimate). If `bias` is 1,
        then normalization is by ``N``. This keyword can be overridden by
        the keyword ``ddof`` in numpy versions >= 1.5.
    allow_masked : bool, optional
        If True, masked values are propagated pair-wise: if a value is masked
        in `x`, the corresponding value is masked in `y`.
        If False, raises an exception.
    ddof : {None, int}, optional
        .. versionadded:: 1.5
        If not ``None`` normalization is by ``(N - ddof)``, where ``N`` is
        the number of observations; this overrides the value implied by
        ``bias``. The default value is ``None``.

    See Also
    --------
    numpy.corrcoef : Equivalent function in top-level NumPy module.
    cov : Estimate the covariance matrix.

    sddof must be an integeriig�?R�RHR�N(R[R�RyR�RKRR�R�RCR�R\tdiagonalR�tsqrttmultiplytouterRRMRzRR)tvarR�(RjR�R�R�R�R�R�R�tctdiagt_denomR�R�R�t_x((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyR
-s@+		+(
!)
>A
;tMAxisConcatenatorcBs#eZdZdd�Zd�ZRS(s�
    Translate slice objects to concatenation along an axis.

    For documentation on usage, see `mr_class`.

    See Also
    --------
    mr_class

    icCstj||dt�dS(Ntmatrix(R=RYRC(RWRH((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyRY�sc
Cs�t|t�rtd��nt|�tk	r<|f}ng}g}d}xtt|��D]}t}t||�t	kr1||j
}||j}||j}	|dkr�d}n|dkr�d}nt|�td�krt
t|��}
tj||	d|
�}qtj||	|�}n�t||�tkr�||dkryt|_||dk|_qanyt
||�|_waWqttfk
r�td��qXnLt||�tjkr�t||g�}|j|�t}n
||}|j|�t|t�ra|ra|dkrC|j}qa|j|kra|j}qaqaqaW|dk	r�x(|D]}||j|�||<qxWntt|�d	|j�}|j|�S(
NsUnavailable for masked array.iiy�?tnumtrcR�sUnknown special directiveRH( R?tstrR+ttypeR@R[RzRcRCR|tsteptstarttstopR�tabsRKtlinspacetarangeRBR�tcolRHRyR�t
ScalarTypeR.ReR<RNR�R/t_retval(
RWtkeytobjstscalarstfinal_dtypedescrRstscalarRRRR�tnewobjRn((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyt__getitem__�s^


			
	


(RTRpRVRYR(((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyR��s
tmr_classcBseZdZd�ZRS(sG
    Translate slice objects to concatenation along the first axis.

    This is the masked array version of `lib.index_tricks.RClass`.

    See Also
    --------
    lib.index_tricks.RClass

    Examples
    --------
    >>> np.ma.mr_[np.ma.array([1,2,3]), 0, 0, np.ma.array([4,5,6])]
    array([1, 2, 3, 0, 0, 4, 5, 6])

    cCstj|d�dS(Ni(R�RY(RW((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyRY�s(RTRpRVRY(((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyR�scCszt|�}|tks(tj|�rBtjd|jdg�Stj|�}t|�dkrr|ddgSdSdS(s�
    Find the indices of the first and last unmasked values.

    Expects a 1-D `MaskedArray`, returns None if all values are masked.

    Parameters
    ----------
    arr : array_like
        Input 1-D `MaskedArray`

    Returns
    -------
    edges : ndarray or None
        The indices of first and last non-masked value in the array.
        Returns None if all values are masked.

    See Also
    --------
    flatnotmasked_contiguous, notmasked_contiguous, notmasked_edges,
    clump_masked, clump_unmasked

    Notes
    -----
    Only accepts 1-D arrays.

    Examples
    --------
    >>> a = np.ma.arange(10)
    >>> flatnotmasked_edges(a)
    [0,-1]

    >>> mask = (a < 3) | (a > 8) | (a == 5)
    >>> a[mask] = np.ma.masked
    >>> np.array(a[~a.mask])
    array([3, 4, 6, 7, 8])

    >>> flatnotmasked_edges(a)
    array([3, 8])

    >>> a[:] = np.ma.masked
    >>> print flatnotmasked_edges(ma)
    None

    iii����N(	R2R8RKR�R-R�tflatnonzeroRcR[(RORItunmasked((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyR�s-cCs�t|�}|dks'|jdkr1t|�St|�}ttj|j�dtj|g|j��}t	gt
|j�D]}||j|�j�^q��t	gt
|j�D]}||j
|�j�^q��gS(sg
    Find the indices of the first and last unmasked values along an axis.

    If all values are masked, return None.  Otherwise, return a list
    of two tuples, corresponding to the indices of the first and last
    unmasked values respectively.

    Parameters
    ----------
    a : array_like
        The input array.
    axis : int, optional
        Axis along which to perform the operation.
        If None (default), applies to a flattened version of the array.

    Returns
    -------
    edges : ndarray or list
        An array of start and end indexes if there are any masked data in
        the array. If there are no masked data in the array, `edges` is a
        list of the first and last index.

    See Also
    --------
    flatnotmasked_contiguous, flatnotmasked_edges, notmasked_contiguous,
    clump_masked, clump_unmasked

    Examples
    --------
    >>> a = np.arange(9).reshape((3, 3))
    >>> m = np.zeros_like(a)
    >>> m[1:, 1:] = 1

    >>> am = np.ma.array(a, mask=m)
    >>> np.array(am[~am.mask])
    array([0, 1, 2, 3, 6])

    >>> np.ma.extras.notmasked_edges(ma)
    array([0, 6])

    iRJN(R.R[RxRR3R-RKtindicesRMR@Rztmint
compressedR�(RORHRIR�R�((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyR!s*
18cCs�t|�}|tkr+td|jd�Sd}g}xbtj|j��D]K\}}tt	|��}|s�|j
t|||��n||7}qMW|p�dS(sr
    Find contiguous unmasked data in a masked array along the given axis.

    Parameters
    ----------
    a : narray
        The input array.

    Returns
    -------
    slice_list : list
        A sorted sequence of slices (start index, end index).

    See Also
    --------
    flatnotmasked_edges, notmasked_contiguous, notmasked_edges,
    clump_masked, clump_unmasked

    Notes
    -----
    Only accepts 2-D arrays at most.

    Examples
    --------
    >>> a = np.ma.arange(10)
    >>> np.ma.extras.flatnotmasked_contiguous(a)
    slice(0, 10, None)

    >>> mask = (a < 3) | (a > 8) | (a == 5)
    >>> a[mask] = np.ma.masked
    >>> np.array(a[~a.mask])
    array([3, 4, 6, 7, 8])

    >>> np.ma.extras.flatnotmasked_contiguous(a)
    [slice(3, 5, None), slice(6, 9, None)]
    >>> a[:] = np.ma.masked
    >>> print np.ma.extras.flatnotmasked_edges(a)
    None

    iN(R2R8R|R�R[t	itertoolstgroupbyR�RcRARe(RORIR�R�RstgR�((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyRLs)"cCs�t|�}|j}|dkr0td��n|dksH|dkrRt|�Sg}|dd}ddg}tdd�||<xBt|j|�D]-}|||<|jt||�p�d�q�W|S(s�
    Find contiguous unmasked data in a masked array along the given axis.

    Parameters
    ----------
    a : array_like
        The input array.
    axis : int, optional
        Axis along which to perform the operation.
        If None (default), applies to a flattened version of the array.

    Returns
    -------
    endpoints : list
        A list of slices (start and end indexes) of unmasked indexes
        in the array.

    See Also
    --------
    flatnotmasked_edges, flatnotmasked_contiguous, notmasked_edges,
    clump_masked, clump_unmasked

    Notes
    -----
    Only accepts 2-D arrays at most.

    Examples
    --------
    >>> a = np.arange(9).reshape((3, 3))
    >>> mask = np.zeros_like(a)
    >>> mask[1:, 1:] = 1

    >>> ma = np.ma.array(a, mask=mask)
    >>> np.array(ma[~ma.mask])
    array([0, 1, 2, 3, 6])

    >>> np.ma.extras.notmasked_contiguous(ma)
    [slice(0, 4, None), slice(6, 7, None)]

    is%Currently limited to atmost 2D array.iiN(	R.RxR�R[RR|RzRMRe(RORHR�R�totherR�R�((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyR �s)	

!cCs�|jdkr|j�}n|d|d j�}|dd}gttjdg|�tj|t|�g��D]\}}t||�^qx}|S(sv
    Finds the clumps (groups of data with the same values) for a 1D bool array.

    Returns a series of slices.
    ii����i(RxR�R�tzipRtchainRcR|(RJR�tlefttrighttslices((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyt_ezclump�s=cCszt|dt�}|tkr1td|j�gSt|�}|dtkrc|ddd�}n|ddd�}|S(s�
    Return list of slices corresponding to the unmasked clumps of a 1-D array.
    (A "clump" is defined as a contiguous region of the array).

    Parameters
    ----------
    a : ndarray
        A one-dimensional masked array.

    Returns
    -------
    slices : list of slice
        The list of slices, one for each continuous region of unmasked
        elements in `a`.

    Notes
    -----
    .. versionadded:: 1.4.0

    See Also
    --------
    flatnotmasked_edges, flatnotmasked_contiguous, notmasked_edges,
    notmasked_contiguous, clump_masked

    Examples
    --------
    >>> a = np.ma.masked_array(np.arange(10))
    >>> a[[0, 1, 2, 6, 8, 9]] = np.ma.masked
    >>> np.ma.extras.clump_unmasked(a)
    [slice(3, 6, None), slice(7, 8, None)]

    RRiiNi(RZR8R|R�R R5(RORJRR�((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyR�s!cCswtj|�}|tkrgSt|�}t|�rs|dtkr]|ddd�}qs|ddd�}n|S(s
    Returns a list of slices corresponding to the masked clumps of a 1-D array.
    (A "clump" is defined as a contiguous region of the array).

    Parameters
    ----------
    a : ndarray
        A one-dimensional masked array.

    Returns
    -------
    slices : list of slice
        The list of slices, one for each continuous region of masked elements
        in `a`.

    Notes
    -----
    .. versionadded:: 1.4.0

    See Also
    --------
    flatnotmasked_edges, flatnotmasked_contiguous, notmasked_edges,
    notmasked_contiguous, clump_unmasked

    Examples
    --------
    >>> a = np.ma.masked_array(np.arange(10))
    >>> a[[0, 1, 2, 6, 8, 9]] = np.ma.masked
    >>> np.ma.extras.clump_masked(a)
    [slice(0, 3, None), slice(6, 7, None), slice(8, 10, None)]

    iNii(R\R2R8R RcR5(RORJR((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyR�s!cCs;tj||�}t|�}|tk	r7d||<n|S(sC
    Masked values in the input array result in rows of zeros.
    i(RKR(R2R8(RjR�t_vanderRI((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyR(,s

c	Csit|�}t|�}t|�}|jdkrKt|t|��}n^|jdkr�tt|��}|tk	r�t||dd�df�}q�ntd��|dk	rt|�}|jdkr�td�n|jd|jdkrtd�nt|t|��}n|tk	rJ|dk	r@||}qJ|}nt	j
|||||||�S(sD
    Any masked values in x is propagated in y, and vice-versa.
    iiNis Expected a 1D or 2D array for y!s expected a 1-d array for weightss(expected w and y to have the same length(R.R2RxR7RR8R�R[RMRKR"(	RjR�tdegtrcondtfullR�RRItmy((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyR"8s,%
((\RVt
__author__t__version__t__revision__t__date__t__all__RtwarningstcoreR\R*R+R,R-R.R/R0R1R2R3R4R5R6R7R8R9R:R;tnumpyRKR<R�tnumpy.core.umathR�tnumpy.lib.index_tricksR=tnumpy.linalgR>RER[RR�RRRSRRRR)R#RRRRRRtRRRCRRR
RR	RRRRRR&RR%RR'R$RBR�RR
R�RRRR!RR R RRR(tdoc_noteR"(((s5/usr/lib64/python2.7/site-packages/numpy/ma/extras.pyt<module>
s�		v	63	:I	
	U	�ZD		Z-.> $	%+IZB		73	5<		,	2	!