Ñò \ÐKc,@sxdZdZdZdZdZddddd d d d d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0g,Zd1d2kZd1d2kZd1d2kZ d1d3kl Z l Z l Z l Z lZlZlZlZlZlZlZlZlZlZlZlZlZlZd1d2kZd1d4klZl Zd1d2k ii!Z!d1d5k"l#Z#d1d6k$l%Z%d1d7k&l'Z'd8„Z(d2d9„Z*e+d:„Z,d;„Z-d<dcd=„ƒYZ.ei/Z/ei0Z0ei1Z1e.d0ƒZ2Z3e.dƒZ4e.d ƒZ5e.dƒZ6e.dƒZ7e.dƒZ8d>„Z9d?„Z:ei:ie:_d2d2e;d@„Z<d2d2e;dA„Z=d2dB„Z>dC„Z?dD„Z@d2dE„ZAd2dF„ZBd2dG„ZCe;dH„ZDd2d2dI„ZEe;e;dJ„ZFe;dK„ZGe;dL„ZHe;dM„ZIdN„ZJe;dO„ZKe'e;e;dP„ƒZLe'dQ„ƒZMe'dR„ƒZNd2eOeOdS„ZPd2eOe;eOdT„ZQd2eOe;eOdU„ZRdVe#fdW„ƒYZSdXeSfdY„ƒYZTeTƒZUdZ„ZVd2d[„ZWd\„ZXd2d]„ZYd^„ZZd_„Z[d`„Z\d2da„Z]e i^ei]ie]iƒe]_d2e;db„Z_e i^ei_ie_iƒe__d2S(dsË 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_axist atleast_1dt atleast_2dt atleast_3dtaveraget clump_maskedtclump_unmaskedt column_stackt compress_colstcompress_rowcolst compress_rowst count_maskedtcorrcoeftcovtdiagflattdottdstacktediff1dtflatnotmasked_contiguoustflatnotmasked_edgesthsplitthstacktin1dt intersect1dtintersect1d_nut mask_colst mask_rowcolst mask_rowst masked_alltmasked_all_liketmediantmr_tnotmasked_contiguoustnotmasked_edgestpolyfitt row_stackt setdiff1dt setmember1dtsetxor1dtuniquetunique1dtunion1dtvandertvstackiÿÿÿÿN(t MaskedArraytMAErrortaddtarraytasarrayt concatenatetcounttfilledtgetmaskt getmaskarraytmake_mask_descrtmaskedt masked_arraytmask_ortnomasktonestsorttzeros(tndarrayR/(tAxisConcatenator(tlstsq(t deprecatecCs"t|tttfƒotStS(s+Is seq a sequence (ndarray, list or tuple)?(t isinstanceR>ttupletlisttTruetFalse(tseq((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyt issequence6scCst|ƒ}|i|ƒ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]) (R5tsum(tarrtaxistm((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyR <s3 cCs4tti||ƒdti|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(R8tnptemptyR;R6(tshapetdtypeta((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyRrs/cCs@ti|ƒitƒ}ti|idt|iƒƒ|_|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') RQ( RNt empty_liketviewR,R;RPR6RQt_mask(RJRR((s5/usr/lib64/python2.6/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||_|iƒ|_dS(N(t__name__tgetdoct__doc__(tselftfuncname((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyt__init__ðs cCsett|idƒ}t|ddƒ}|o3|iti|ƒ}d}di|||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 RYsLNotes ----- The function is applied to both the _data and the _mask, if any.s N(tgetattrRNRWtNonetmatget_object_signaturetjoin(RZtnpfunctdoctsigtlocdoc((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyRXôsc Osàtt|iƒ}t|ƒdjoü|d}t|tƒo>|ti|ƒ|}|t|ƒ|}t|d|ƒSt|t ƒpt|t ƒo€|t g}|D]}|ti|ƒq®~ƒ|}|t g} |D]}| t|ƒqç~ ƒ|}t|d|ƒSn¼g} t |ƒ}x?t|ƒdjo+t |dƒo| i |i dƒƒq6Wg} xZ| D]R}|ti|ƒ||Ž}|t|ƒ||Ž}| i t|d|ƒƒq‚W| SdS(NiiRM(R]RNRWtlenRBR>R0R5R8RCRDRHtappendtpop( RZtargstparamstfunctxt_dt_mt_[1]RRt_[2]tarraystres((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyt__call__s.  96 $(RWt __module__RYR\RXRs(((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyRVßs  cCs`d}xS|t|ƒjo?x.t||dƒo|||||d+qW|d7}q W|S(sFlatten a sequence in place.it__iter__i(Rfthasattr(RGtk((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pytflatten_inplace<sc OsÓt|dtdtƒ}|i}|djo||7}n||jotd||fƒ‚ndg|d}ti|dƒ}t|ƒ}|i|ƒt d d ƒ|||idƒidd ƒ}tt i i |i ƒƒƒ}qmtt|dƒtd|ƒi ƒ}t i |i ƒ|ƒ}t i |ƒ}~n|tjoo|d jo-||d}t i |i |dtƒ}qmt|dƒ}|i} | djo d} n| |joGti|tddƒ}t i |||ƒ}t i ||ƒ}~qm| ||fjo‘||} d gt|ƒ} td d dƒ| |t|dƒ}|i} | djo d} n| |joVt|dtd|ddƒ}t i |||dtƒ}t i ||dtƒ}n©| ||fjo‹||} d gt|ƒ} td d dƒ| |>> 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] iRKgiRMgð?RQRysw[s] * ones(ash, float)saverage: weights wrong shape.s(] * masked_array(ones(ash, float), mask)N((i((i((i(R0RMRPR^R:RItfloattsizeR3traveltumathR.treducet_dataR/RNRfR€tevaltreprRCR}R7RBR,R|R8R>R;( RRRKtweightstreturnedRMtashR—tdtwtwshtnitrRš((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyRžs 1         #$           #        * $% cCs­d„}|oA|djo|iƒ}|iƒqc|id|ƒ|}nt|d|ƒ}|djo||ƒ}nt|||ƒ}|dj o |}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) cSsptt|ƒdƒ}t|dƒ\}}|ot||dƒ}nt|d|dƒ}||idƒS(Niii(R3R2tdivmodR€tmean(tdatatcountstidxtrmdtchoice((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyt _median1Dis RKN(R^RR<R(RRRKtouttoverwrite_inputR²tasortedRš((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyR-s<       cCs/t|ƒ}|idjo td‚nt|ƒ}|tjp|iƒ o|iS|iƒo tgƒSt t |ƒƒt |i dƒ}}|i ƒ}|p/x,t i|dƒD]}|i|ƒq½Wn|djo/x,t i|dƒD]}|i|ƒqùWn|i|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ÿÿÿÿ(R0R|tNotImplementedErrorR4R:tanyR talltnxarrayR~RfRPtnonzeroRNR'RR^(RlRKRLtidxrtidxcR7RR’((s5/usr/lib64/python2.6/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 (RR((s5/usr/lib64/python2.6/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 (RR((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyRÙs cCsÍt|ƒ}|idjo td‚nt|ƒ}|tjp|iƒ o|S|iƒ}|iiƒ|_|pt |t i |dƒ>> 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ÿÿÿÿ( R0R|R¶R4R:R·RºRURyR7RNR'R^(RRRKRLt maskedval((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyRçsK     '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(RRRK((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyRAs+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(RRRK((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyRns+cCs¤|o<|idjo,|idjot|ƒ}t|ƒ}ntit|dƒt|dƒƒ}t|ƒ}t|ƒ}ti||ƒ}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) iiRM(R|RRRNRR3R5R8(RRtbtstrictR¦tamtbmRL((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyRœs/' $  cCs“ti|ƒi}|d|d }|g}|dj o|id|ƒn|dj o|i|ƒnt|ƒdjot|ƒ}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^tinsertRgRfR(RJtto_endtto_begintedRq((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyRÚs    cCsqti|d|d|ƒ}t|tƒo3t|ƒ}|ditƒ|d>> 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) iiÿÿÿÿ(R_R1R'R<(RÊtar2t assume_uniquetaux((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyRs ! cCs«|pt|ƒ}t|ƒ}nti||fƒ}|idjo|S|iƒ|iƒ}titg|d|d jtgfƒ}|d|d j}||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_R1RœR<R3RE(RÊRÌRÍRÎtauxftflagtflag2((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyR&/s    ,c CsÈ|p(t|dtƒ\}}t|ƒ}nti||fƒ}|iddƒ}||}|d|d j}ti|tgfƒ}|iddƒt|ƒ } |o || 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'RER_R1targsortRFRf( RÊRÌRÍtrev_idxtartordertsart equal_adjRÐtindx((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyRIs  cCstti||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_R1(RÊRÌ((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyR)ms cCsh|pt|ƒ}t|ƒ}nt||dtƒ}|idjo|Sti|ƒ|djSdS(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'RRERœR_R0(RÊRÌRÍRÎ((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyR${s cCsqti|d|d|ƒ}t|tƒo3t|ƒ}|ditƒ|dRQRçR1t_retval( RZtkeytobjstscalarstfinal_dtypedescrRwtscalarRR R RœtnewobjRr((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyt __getitem__sb                 (RWRtRYR\R(((s5/usr/lib64/python2.6/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]) cCsti|dƒdS(Ni(RR\(RZ((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyR\Ðs(RWRtRYR\(((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyRÀscCsot|ƒ}|tjpti|ƒ o ddgSti|ƒ}t|ƒdjo|ddgSdSdS(sn 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 Notes ----- Only accepts 1-D arrays. Examples -------- >>> a = np.arange(10) >>> mask = (a < 3) | (a > 8) | (a == 5) >>> ma = np.ma.array(a, mask=m) >>> np.array(ma[~ma.mask]) array([3, 4, 6, 7, 8]) >>> flatnotmasked_edges(ma) array([3, 8]) >>> ma = np.ma.array(a, mask=np.ones_like(a)) >>> print flatnotmasked_edges(ma) None iiÿÿÿÿN(R4R:RNR·t flatnonzeroRfR^(RRRLtunmasked((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyRÙs*  c Csõt|ƒ}|djp|idjo t|ƒSt|ƒ}tti|iƒdti|g|iƒƒ}t g}t |iƒD] }|||i |ƒi ƒqˆ~ƒt g}t |iƒD] }|||i |ƒi ƒqÈ~ƒgS(sE 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 Examples -------- >>> a = np.arange(9).reshape((3, 3)) >>> m = np.zeros_like(a) >>> m[1:, 1:] = 1 >>> ma = np.ma.array(a, mask=m) >>> np.array(ma[~ma.mask]) array([0, 1, 2, 3, 6]) >>> np.ma.extras.notmasked_edges(ma) array([0, 6]) iRMN(R0R^R|RR5R/RNtindicesRPRCR~tmint compressedRˆ(RRRKRLR¯RoRRp((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyR! s)   1@c Csät|ƒ}|tjo|iddgfSti|ƒ}t|ƒdjodSg}xxtit |ƒd„ƒD][\}}ti g}|D]}||dq”~t ƒ}|i t |d|dƒƒqwW|iƒ|S(s& 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 Notes ----- Only accepts 2-D arrays at most. Examples -------- >>> a = np.arange(10) >>> mask = (a < 3) | (a > 8) | (a == 5) >>> ma = np.ma.array(a, mask=mask) >>> np.array(ma[~ma.mask]) array([3, 4, 6, 7, 8]) >>> np.ma.extras.flatnotmasked_contiguous(ma) [slice(3, 4, None), slice(6, 8, None)] >>> ma = np.ma.array(a, mask=np.ones_like(a)) >>> print np.ma.extras.flatnotmasked_edges(ma) None iiÿÿÿÿcSs|\}}||S(((t.0RRl((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pytksiN(R4R:RœRNRRfR^t itertoolstgroupbyt enumerateR/RäRgR€R<( RRRLRRšRwtgroupRotgttmp((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyR?s%   1" cCsÊt|ƒ}|i}|djo td‚n|djp |djo t|ƒSg}|dd}ddg}tddƒ||>> 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, 3, None), slice(6, 6, None)] is%Currently limited to atmost 2D array.iiN( R0R|R¶R^RR€R~RPRg(RRRKRRštotherR¯R((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyR rs(       c Cs§|idjo|iƒ}n|d|d iƒ}|dd}g}ttidg|ƒti|t|ƒgƒƒD]\}}|t||ƒq~~}|S(sv Finds the clumps (groups of data with the same values) for a 1D bool array. Returns a series of slices. iiÿÿÿÿi(R|RRºtzipR tchainRfR€(RMR¯Rotlefttrighttslices((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyt_ezclump­sAcCs~t|dtƒ}|tjotd|iƒgSt|ƒ}|dtjo|ddd…}n|ddd…}|S(s9 Return list of slices corresponding to the unmasked clumps of a 1-D 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 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)] RUiiNi(R]R:R€RœR,R7(RRRMR+Rš((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyR¾s  cCs}ti|ƒ}|tjogSt|ƒ}t|ƒo?|dtjo|ddd…}qy|ddd…}n|S(sL Returns a list of slices corresponding to the masked clumps of a 1-D 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 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, None, None)] iNii(R_R4R:R,RfR7(RRRMR+((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyRäs   cCs=ti||ƒ}t|ƒ}|tj od||      #    # ' ! ((`RYt __author__t __version__t __revision__t__date__t__all__R R0tcoreR_R,R-R.R/R0R1R2R3R4R5R6R7R8R9R:R;R<R=tnumpyRNR>R¹tnumpy.core.umathRžtnumpy.lib.index_tricksR?t numpy.linalgR@tnumpy.lib.utilsRARHR^R R›RRRVRRRR+R#RRRRRRxRRFRRR R RRRRRRR'RR&RR)R$R(RR%RERòR R RRRRR!RR R,RRR*tdoc_noteR"(((s5/usr/lib64/python2.6/site-packages/numpy/ma/extras.pyt s¬             v   6 3 :L         UZ D   Z - . >  $   #+8JB  4 2 3 ;  & , ,