K itdZgdZddlZddlZddlZddlmZddlmZddl m Z ddl m Z ddl mZmZd d lmZd d lmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&d Z'dNd Z(e)fdZ*dZ+GddZ,Gdde,Z-Gdde,Z.Gdde,Z/Gdde,Z0e0dZ1e0dZ2e0dZ3e.dxZ4Z5e.dZ6e.dZ7e.d Z8e.d!Z9e-d"Z:e-d#Z;d$Ze>jRej|jdej|jjd'jd(ze>_dOejd)d*ZBdPd+ZCdOd,ZDdNd-ZEdNd.ZFd/ZGd0ZHdNd1ZIejfd2ZJejfd3ZKdQd4ZLdRd5ZMdSd6ZNdSd7ZOdRd8ZPdRd9ZQd:ZRdSd;ZSdTd=ZTdUd>ZUdd>> import numpy as np >>> a = np.arange(9).reshape((3,3)) >>> a = np.ma.array(a) >>> a[1, 0] = np.ma.masked >>> a[1, 2] = np.ma.masked >>> a[2, 1] = np.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) >>> np.ma.count_masked(a) 3 When the `axis` keyword is used an array is returned. >>> np.ma.count_masked(a, axis=0) array([1, 1, 1]) >>> np.ma.count_masked(a, axis=1) array([0, 2, 1]) )rCsum)arraxisms rQrrBsd SA 55;rSc ttj||tj|t |}|S)a 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 : int or tuple of ints Shape of the required MaskedArray, e.g., ``(2, 3)`` or ``2``. 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. Notes ----- Unlike other masked array creation functions (e.g. `numpy.ma.zeros`, `numpy.ma.ones`, `numpy.ma.full`), `masked_all` does not initialize the values of the array, and may therefore be marginally faster. However, the values stored in the newly allocated array are arbitrary. For reproducible behavior, be sure to set each element of the array before reading. Examples -------- >>> import numpy as np >>> np.ma.masked_all((3, 3)) masked_array( data=[[--, --, --], [--, --, --], [--, --, --]], mask=[[ True, True, True], [ True, True, True], [ True, True, True]], fill_value=1e+20, dtype=float64) The `dtype` parameter defines the underlying data type. >>> a = np.ma.masked_all((3, 3)) >>> a.dtype dtype('float64') >>> a = np.ma.masked_all((3, 3), dtype=np.int32) >>> a.dtype dtype('int32') mask)rGnpemptyrIrD)shapedtypeas rQr r xs5p RXXeU+''%)?@ BA HrSctj|jt}tj|j t |j|_|S)aG 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. Notes ----- Unlike other masked array creation functions (e.g. `numpy.ma.zeros_like`, `numpy.ma.ones_like`, `numpy.ma.full_like`), `masked_all_like` does not initialize the values of the array, and may therefore be marginally faster. However, the values stored in the newly allocated array are arbitrary. For reproducible behavior, be sure to set each element of the array before reading. Examples -------- >>> import numpy as np >>> arr = np.zeros((2, 3), dtype=np.float32) >>> arr array([[0., 0., 0.], [0., 0., 0.]], dtype=float32) >>> np.ma.masked_all_like(arr) masked_array( data=[[--, --, --], [--, --, --]], mask=[[ True, True, True], [ True, True, True]], fill_value=np.float64(1e+20), dtype=float32) The dtype of the masked array matches the dtype of `arr`. >>> arr.dtype dtype('float32') >>> np.ma.masked_all_like(arr).dtype dtype('float32') r_) r\ empty_likeviewr:rIr^rDr__mask)rVr`s rQr!r!sBv c ,Aggagg_QWW%=>AG HrSc"eZdZdZdZdZdZy)_fromnxfunctionaV 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`. This class should not be used directly. Instead, one of its extensions that provides support for a specific type of input should be used. Parameters ---------- funcname : str The name of the function to be adapted. The function should be in the NumPy namespace (i.e. ``np.funcname``). cJ||_||_|j|_yN)__name__ __qualname__getdoc__doc__)selffuncnames rQ__init__z_fromnxfunction.__init__ s  ${{} rSctt|jd}t|dd}|rDtj|}tj |d}|r|j|zdz}||zSy)aK 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. Parameters ---------- None Nrmz@The function is applied to both the _data and the _mask, if any.z )getattrr\rjmaget_object_signaturedoc_note)rnnpfuncdocsigs rQrlz_fromnxfunction.getdocsoT]]D1fi. ))&1C++c$<=Cmmc)F29 rScyri)rnargsparamss rQ__call__z_fromnxfunction.__call__)s rSN)rj __module__rkrmrprlr}rzrSrQrgrgs&% 0 rSrgceZdZdZdZy)_fromnxfunction_singlez A version of `_fromnxfunction` that is called with a single array argument followed by auxiliary args that are passed verbatim for both the data and mask calls. cPtt|j}t|tr<||j g|i|}|t |g|i|}t||S|tj|g|i|}|t |g|i|}t||S)NrZ) rrr\rjrMr2 __array__rCrGr<rnxr{r|func_d_ms rQr}z_fromnxfunction_single.__call__3sr4==) a !akkm5d5f5Bl1o777B, ,bjjm5d5f5Bl1o777B, ,rSNrjr~rkrmr}rzrSrQrr-s  -rSrceZdZdZdZy)_fromnxfunction_seqz A version of `_fromnxfunction` that is called with a single sequence of arrays followed by auxiliary args that are passed verbatim for both the data and mask calls. ctt|j}|td|Dg|i|}|td|Dg|i|}t ||S)Nc3FK|]}tj|ywri)r\r<.0r`s rQ z/_fromnxfunction_seq.__call__..Gs1! 1 1s!c32K|]}t|ywri)rCrs rQrz/_fromnxfunction_seq.__call__..Hs3A Q3srZ)rrr\rjrNrGrs rQr}z_fromnxfunction_seq.__call__Es]r4==) %1q11 CD CF C %333 Ed Ef EBR((rSNrrzrSrQrr?s  )rSrceZdZdZdZy)_fromnxfunction_argsa A version of `_fromnxfunction` that is called with multiple array arguments. The first non-array-like input marks the beginning of the arguments that are passed verbatim for both the data and mask calls. Array arguments are processed independently and the results are returned in a list. If only one array is found, the return value is just the processed array instead of a list. ctt|j}g}t|}t |dkDrKt |dr=|j |jdt |dkDrt |dr=g}|D]R}|tj|g|i|}|t|g|i|}|j t||Tt |dk(r|dS|S)Nr0rZr7) rrr\rjrOlenrRappendpopr<rCrG) rnr{r|rarraysresrrrs rQr}z_fromnxfunction_args.__call__Usr4==)Dz$i!m 47 3 MM$((1+ &$i!m 47 3 2Abjjm5d5f5Bl1o777B JJ|BR0 1 2 v;! q6M rSNrrzrSrQrrLs  rSrceZdZdZdZy)_fromnxfunction_allargsa A version of `_fromnxfunction` that is called with multiple array arguments. Similar to `_fromnxfunction_args` except that all args are converted to arrays even if they are not so already. This makes it possible to process scalars as 1-D arrays. Only keyword arguments are passed through verbatim for the data and mask calls. Arrays arguments are processed independently and the results are returned in a list. If only one arg is present, the return value is just the processed array instead of a list. ctt|j}g}|D]L}|tj|fi|}|t |fi|}|j t ||Nt|dk(r|dS|S)NrZr7r0)rrr\rjr<rCrrGr)rnr{r|rrrrrs rQr}z _fromnxfunction_allargs.__call__ps~r4==) 2Abjjm.v.Bl1o00B JJ|BR0 1 2 t9>q6M rSNrrzrSrQrres   rSrrrrr/rr rr+rrcd}|t|k7r>t||dr|||||dzt||dr|dz }|t|k7r>|S)zFlatten a sequence in place.r0__iter__r7)rhasattr)rPks rQflatten_inplacers` A C=c!fj) VC1q5Nc!fj) Q C= JrSc^ t|dd}|j}t||}dg|dz z}tj|d}t t |}|j|tdd||<tj|jj|} |j||||t|jg|i|} tj| } | s t!| g} | r0| j%tj| j&t | t(} | | t|<tj*| }d}||kr|dxxdz cc<d}||| |k\r6|d|z kDr.||dz xxdz cc<d||<|dz}||| |k\r |d|z kDr.|j||||t|jg|i|} | | t|<| j%t| j&|dz }||krŐnt| dd} |j-}tddg| jz||<|j||tj*| }| }t |j} | j| |<| j%t| j&t/| } t | t(} | | tt/|j<d}||kr|dxxdz cc<d}||||k\r6|d|z kDr.||dz xxdz cc<d||<|dz}||||k\r |d|z kDr.|j|||j||||t|jg|i|} | | tt/|j<| j%t| j&|dz }||krtj&tj| j1}t3|d stj| | }|St| | }t5j6||_|S#t"$rd} YwxYw) z0 (This docstring should be overwritten) FT)copysubokr0r7ONrerb)r1ndimr5r\rKrOrangeremoveslicer<r^takeputrNtolistisscalarr TypeErrorrr_objectprodrrmaxrrsdefault_fill_value fill_value)func1drWrVr{kwargsndindiindlistoutshaperasscalardtypesoutarrNtotrnj holdshape max_dtypesresults rQrrs; %t ,C B b )D #a.C SA59oG NN4D$AdGzz#))$))'2HEE'3 U188:&' 9$ 9& 9C{{3H   H F bjjo++,x( uSzwwx  $h GqLGAq6Xa[(qAF|AE a AQq6Xa[(qAF| EE'3 U188:./A$A&AC!$F5:  MM'#,,, - FA$hCe40 FFH$%&1$ gswwx   ? gcl(()"8,x(58u_QXXZ012 $h GqLGAq6Yq\)QV AE a AQq6Yq\)QV  EE'3  EE'3 U188:./A$A&AC9>> import numpy as np >>> a = np.ma.arange(24).reshape(2,3,4) >>> a[:,0,1] = np.ma.masked >>> a[:,1,:] = np.ma.masked >>> a masked_array( data=[[[0, --, 2, 3], [--, --, --, --], [8, 9, 10, 11]], [[12, --, 14, 15], [--, --, --, --], [20, 21, 22, 23]]], mask=[[[False, True, False, False], [ True, True, True, True], [False, False, False, False]], [[False, True, False, False], [ True, True, True, True], [False, False, False, False]]], fill_value=999999) >>> np.ma.apply_over_axes(np.ma.sum, a, [0,2]) masked_array( data=[[[46], [--], [124]]], mask=[[[False], [ True], [False]]], fill_value=999999) Tuple axis arguments to ufuncs are equivalent: >>> np.ma.sum(a, axis=(0,2)).reshape((1,-1,1)) masked_array( data=[[[46], [--], [124]]], mask=[[[False], [ True], [False]]], fill_value=999999) )keepdimsc>tt}tjd|tj uri}nd|i}|?j fi|}|jjj}nt|} tjjtjtjfr,t jj| jd} n*t jj| j} j| jk7r td| jt!fdDk7r t#d| j%t j&} | j)t!fdt+jD} |t,ur/| j.z} | xj.j.zc_| j0d | d |}t j2| | j0fi||z }|rK|j|jk7r.t j4||jj7}||fS|S) aK 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 : None or int or tuple of ints, optional Axis or axes along which to average `a`. The default, `axis=None`, will average over all of the elements of the input array. If axis is a tuple of ints, averaging is performed on all of the axes specified in the tuple instead of a single axis or all the axes as before. weights : array_like, optional An array of weights associated with the values in `a`. Each value in `a` contributes to the average according to its associated weight. The array of weights must be the same shape as `a` if no axis is specified, otherwise the weights must have dimensions and shape consistent with `a` along the specified axis. If `weights=None`, then all data in `a` are assumed to have a weight equal to one. The calculation is:: avg = sum(a * weights) / sum(weights) where the sum is over all included elements. The only constraint on the values of `weights` is that `sum(weights)` must not be 0. 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. keepdims : bool, optional If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original `a`. *Note:* `keepdims` will not work with instances of `numpy.matrix` or other classes whose methods do not support `keepdims`. .. versionadded:: 1.23.0 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 and floats smaller than `float64`, or the input data-type, otherwise. If returned, `sum_of_weights` is always `float64`. Raises ------ ZeroDivisionError When all weights along axis are zero. See `numpy.ma.average` for a version robust to this type of error. TypeError When `weights` does not have the same shape as `a`, and `axis=None`. ValueError When `weights` does not have dimensions and shape consistent with `a` along specified `axis`. Examples -------- >>> import numpy as np >>> 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) >>> x masked_array( data=[[0., 1.], [2., 3.], [4., 5.]], mask=False, fill_value=1e+20) >>> data = np.arange(8).reshape((2, 2, 2)) >>> data array([[[0, 1], [2, 3]], [[4, 5], [6, 7]]]) >>> np.ma.average(data, axis=(0, 1), weights=[[1./4, 3./4], [1., 1./2]]) masked_array(data=[3.4, 4.4], mask=[False, False], fill_value=1e+20) >>> np.ma.average(data, axis=0, weights=[[1./4, 3./4], [1., 1./2]]) Traceback (most recent call last): ... ValueError: Shape of weights must be consistent with shape of a along specified axis. >>> avg, sumweights = np.ma.average(x, axis=0, weights=[1, 2, 3], ... returned=True) >>> avg masked_array(data=[2.6666666666666665, 3.6666666666666665], mask=[False, False], fill_value=1e+20) With ``keepdims=True``, the following result has shape (3, 1). >>> np.ma.average(x, axis=1, keepdims=True) masked_array( data=[[0.5], [2.5], [4.5]], mask=False, fill_value=1e+20) rW)argnamerf8z;Axis must be specified when shapes of a and weights differ.c3<K|]}j|ywri)r^)raxr`s rQrzaverage..s!="!''"+!=szIShape of weights must be consistent with shape of a along specified axis.c34K|]\}}|vr|ndyw)r7Nrz)rrsrWs rQrzaverage..s*$E(-A+-*Q!%;$Es)rWr_rbrz)r<rBr6rr\_NoValuemeanr_typer> issubclassintegerbool result_typer^rrNr transposeargsortreshape enumeraterHr[rUmultiply broadcast_tor) r`rWweightsreturnedrrX keepdims_kwavgsclwgt result_dtypes `` rQrr8s2b  A A #D!&&&A2;; !8, affT)[)iinnQWWT]+g aggllRZZ$9 :>>!''399dCL>>!''399=L 77cii |yyE!=!=== 788 -- 4 01C++e$E1:1771C$EEFC F?!&&/C HH HcggC4|C{C2bkk!S ,..1c$G:EGILM 99 !//#syy1668CCx rSct|ds]tjt|d||||}t |tj rd|j kr t|dS|St|t||||S) a7 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. keepdims : bool, optional If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array. 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 -------- >>> import numpy as np >>> x = np.ma.array(np.arange(8), mask=[0]*4 + [1]*4) >>> np.ma.median(x) 1.5 >>> x = np.ma.array(np.arange(10).reshape(2, 5), mask=[0]*6 + [1]*4) >>> np.ma.median(x) 2.5 >>> np.ma.median(x, axis=-1, overwrite_input=True) masked_array(data=[2.0, 5.0], mask=[False, False], fill_value=1e+20) r[Tr)rWoutoverwrite_inputrr7Fr)rrrWrr) rr\r"rArMr2rrGr3_median)r`rWrrrrXs rQr"r"svB 1f  IIgat,4' ) a $aff. .H AGhTs$3 55rSc&tj|jtjrtj}nd}|r;#|j j |n$|j ||nt ||dntjjdk(rXtdgjz}tdd|<t|}tjj||Sjdk(r-ttd\}}||zdz |dz}tjjtjrhj dkDrY|j#|} |stj$| dd | } tj&j(j+| } n|j|} tjj-| r>tj.j0stjj3S| Std } | dz} | dzdk(}tj4|| | dz } tj6| | g } tj8|  }fd}||tjjtjr|tjj#||} tj$| j:dd| j: tj&j(j+| } | Stjj||} | S)N)r)rWrr0)rWrr7)rg@safe)castingrTrWrrWctjj|rltjjd|jz}tjj |j |<d|j|<yy)NTrF)r\rs is_maskedallr[minimum_fill_valuedata)rrepasortedrWs rQreplace_maskedz_median..replace_maskedkse 55??1 FF7<sizerU true_dividelib _utils_impl_median_nancheckrrr[rwherer=take_along_axisr)r`rWrrrindexeridxoddmidrcountshllhlow_highrrs ` @rQrr.s }}QWWbjj)VV   <ggiG LLJL / FFF 4Gqt ; |#D',,7}}Ta;-',,.a  .uuzz''*3z??||q%.!,ScCi!mC!G, == 3 q8HC ANN1b&cB""33GQEAS!A 55??1 bffW\\&:55++G4 4 7 5F! A 1*/C aQA AT *B!!'2D9H 8 }}W]]BJJ/ EEIIhTsI 3 qvvr8@ FF   / /D A H EEJJxdJ 4 HrSc t|}t|}|tt|j}nt ||j}|t us|js |jS|jr tgS|j}|D]i}ttt|tt|dz|jz}|tdf|z|j|fz}k|S)a=Suppress slices from multiple dimensions which contain masked values. Parameters ---------- x : array_like, MaskedArray The array to operate on. If not a MaskedArray instance (or if no array elements are masked), `x` is interpreted as a MaskedArray with `mask` set to `nomask`. axis : tuple of ints or int, optional Which dimensions to suppress slices from can be configured with this parameter. - If axis is a tuple of ints, those are the axes to suppress slices from. - If axis is an int, then that is the only axis to suppress slices from. - If axis is None, all axis are selected. Returns ------- compress_array : ndarray The compressed array. Examples -------- >>> import numpy as np >>> arr = [[1, 2], [3, 4]] >>> mask = [[0, 1], [0, 0]] >>> x = np.ma.array(arr, mask=mask) >>> np.ma.compress_nd(x, axis=0) array([[3, 4]]) >>> np.ma.compress_nd(x, axis=1) array([[1], [3]]) >>> np.ma.compress_nd(x) array([[3]]) Nr7r) r<rBrNrrr6rHany_datarnxarrayrOr)rrWrXrrrs rQr r sH  A A |U166]##D!&&1 F{!%%'wwuuwr{ 77D@T%)_tE"q&!&&,A'BBCU4[NR'AEEtE,<+<*>>?@ KrScbt|jdk7r tdt||S)a 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 ---------- x : array_like, MaskedArray The array to operate on. If not a MaskedArray instance (or if no array elements are masked), `x` is interpreted as a MaskedArray with `mask` set to `nomask`. Must be a 2D array. axis : int, optional Axis along which to perform the operation. Default is None. Returns ------- compressed_array : ndarray The compressed array. Examples -------- >>> import numpy as np >>> 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.compress_rowcols(x) array([[7, 8]]) >>> np.ma.compress_rowcols(x, 0) array([[6, 7, 8]]) >>> np.ma.compress_rowcols(x, 1) array([[1, 2], [4, 5], [7, 8]]) rz*compress_rowcols works for 2D arrays only.r)r<rNotImplementedErrorr )rrWs rQr r s.fqz!!"NOO qt $$rScdt|}|jdk7r tdt|dS)ay Suppress whole rows of a 2-D array that contain masked values. This is equivalent to ``np.ma.compress_rowcols(a, 0)``, see `compress_rowcols` for details. Parameters ---------- x : array_like, MaskedArray The array to operate on. If not a MaskedArray instance (or if no array elements are masked), `x` is interpreted as a MaskedArray with `mask` set to `nomask`. Must be a 2D array. Returns ------- compressed_array : ndarray The compressed array. See Also -------- compress_rowcols Examples -------- >>> import numpy as np >>> a = np.ma.array(np.arange(9).reshape(3, 3), mask=[[1, 0, 0], ... [1, 0, 0], ... [0, 0, 0]]) >>> np.ma.compress_rows(a) array([[6, 7, 8]]) rz'compress_rows works for 2D arrays only.r0r<rrr r`s rQrrs2B  Avv{!"KLL Aq !!rScdt|}|jdk7r tdt|dS)a Suppress whole columns of a 2-D array that contain masked values. This is equivalent to ``np.ma.compress_rowcols(a, 1)``, see `compress_rowcols` for details. Parameters ---------- x : array_like, MaskedArray The array to operate on. If not a MaskedArray instance (or if no array elements are masked), `x` is interpreted as a MaskedArray with `mask` set to `nomask`. Must be a 2D array. Returns ------- compressed_array : ndarray The compressed array. See Also -------- compress_rowcols Examples -------- >>> import numpy as np >>> a = np.ma.array(np.arange(9).reshape(3, 3), mask=[[1, 0, 0], ... [1, 0, 0], ... [0, 0, 0]]) >>> np.ma.compress_cols(a) array([[1, 2], [4, 5], [7, 8]]) rz'compress_cols works for 2D arrays only.r7rrs rQr r s2F  Avv{!"KLL Aq !!rSct|d}|jdk7r tdt|}|tus|j s|S|j }|jj|_|st|tj|d<|dvr#t|ddtj|df<|S) a 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 as np >>> a = np.zeros((3, 3), dtype=int) >>> a[1, 1] = 1 >>> a array([[0, 0, 0], [0, 1, 0], [0, 0, 0]]) >>> a = np.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=1) >>> np.ma.mask_rowcols(a) masked_array( data=[[0, --, 0], [--, --, --], [0, --, 0]], mask=[[False, True, False], [ True, True, True], [False, True, False]], fill_value=1) Frrz&mask_rowcols works for 2D arrays only.r0)Nr7rNr7) r1rrrBrHrnonzerorerrFr\r,)r`rWrX maskedvals rQrrEsR auAvv{!"JKK AF{!%%' IggllnAG %+"))IaL !" }(.!RYYy| $ $% HrScv|tjurtjdtdt |dS)a 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 as np >>> a = np.zeros((3, 3), dtype=int) >>> a[1, 1] = 1 >>> a array([[0, 0, 0], [0, 1, 0], [0, 0, 0]]) >>> a = np.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=1) >>> np.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=1) TThe axis argument has always been ignored, in future passing it will raise TypeErrorr stacklevelr0r\rwarningswarnDeprecationWarningrr`rWs rQrrs9T 2;;   #$61 F 1 rScv|tjurtjdtdt |dS)a 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 as np >>> a = np.zeros((3, 3), dtype=int) >>> a[1, 1] = 1 >>> a array([[0, 0, 0], [0, 1, 0], [0, 0, 0]]) >>> a = np.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=1) >>> np.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=1) rrr r7r"r&s rQrrs9R 2;;   #$61 F 1 rSctj|j}|dd|ddz }|g}||jd|||j |t |dk7r t |}|S)a 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. Examples -------- >>> import numpy as np >>> arr = np.ma.array([1, 2, 4, 7, 0]) >>> np.ma.ediff1d(arr) masked_array(data=[ 1, 2, 3, -7], mask=False, fill_value=999999) r7Nrr0)rs asanyarrayflatinsertrrr)rVto_endto_beginedrs rQrrsw* --  ! !C QR3s8 BTF a"  f 6{aF^ IrSctj|||}t|tr3t |}|dj t |d<t|}|S|j t }|S)a: 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. Examples -------- >>> import numpy as np >>> a = [1, 2, 1000, 2, 3] >>> mask = [0, 0, 1, 0, 0] >>> masked_a = np.ma.masked_array(a, mask) >>> masked_a masked_array(data=[1, 2, --, 2, 3], mask=[False, False, True, False, False], fill_value=999999) >>> np.ma.unique(masked_a) masked_array(data=[1, 2, 3, --], mask=[False, False, False, True], fill_value=999999) >>> np.ma.unique(masked_a, return_index=True) (masked_array(data=[1, 2, 3, --], mask=[False, False, False, True], fill_value=999999), array([0, 1, 4, 2])) >>> np.ma.unique(masked_a, return_inverse=True) (masked_array(data=[1, 2, 3, --], mask=[False, False, False, True], fill_value=999999), array([0, 1, 3, 1, 2])) >>> np.ma.unique(masked_a, return_index=True, return_inverse=True) (masked_array(data=[1, 2, 3, --], mask=[False, False, False, True], fill_value=999999), array([0, 1, 4, 2]), array([0, 1, 3, 1, 2])) ) return_indexreturn_inverser0)r\r,rMrNrOrdr:)ar1r0r1outputs rQr,r,-skLYYs$0&46F&% f1INN;/q v M[) MrSc|rtj||f}n)tjt|t|f}|j|dd|dd|ddk(S)aY 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 -------- >>> import numpy as np >>> x = np.ma.array([1, 3, 3, 3], mask=[0, 0, 0, 1]) >>> y = np.ma.array([3, 1, 1, 1], mask=[0, 0, 0, 1]) >>> np.ma.intersect1d(x, y) masked_array(data=[1, 3, --], mask=[False, False, True], fill_value=999999) Nrr7)rsr=r,rJ)r2ar2 assume_uniqueauxs rQrr_sa0nnc3Z(nnfSk6#;78HHJ s8CGs3Bx' ((rSc,|st|}t|}tj||fd}|jdk(r|S|j |j }tjdg|dd|ddk7dgf}|dd|ddk(}||S)a 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. Examples -------- >>> import numpy as np >>> ar1 = np.ma.array([1, 2, 3, 2, 4]) >>> ar2 = np.ma.array([2, 3, 5, 7, 5]) >>> np.ma.setxor1d(ar1, ar2) masked_array(data=[1, 4, 5, 7], mask=False, fill_value=999999) Nrr0Tr7r)r,rsr=rrJr?)r2r5r6r7auxfflagflag2s rQr*r*s* SkSk ..#s$ /C xx1} HHJ ::>D6DHSb $9TFC DD !"Xcr "E u:rScT|st|d\}}t|}tj||f}|jd}||}|r |dd|ddk7}n |dd|ddk(}tj||gf} |jddt |} |r| | S| | S)a 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. We recommend using :func:`isin` instead of `in1d` for new code. See Also -------- isin : Version of this function that preserves the shape of ar1. numpy.in1d : Equivalent function for ndarrays. Examples -------- >>> import numpy as np >>> ar1 = np.ma.array([0, 1, 2, 5, 0]) >>> ar2 = [0, 2] >>> np.ma.in1d(ar1, ar2) masked_array(data=[ True, False, True, False, True], mask=False, fill_value=True) T)r1 mergesort)kindr7Nr)r,rsr=rr) r2r5r6invertrev_idxarordersarbool_arr:indxs rQrrs2 c$7 WSk c #B JJKJ (E U)C qr7c#2h&qr7c#2h& >>7VH- .D ==k= *9CH 5DDzDz'""rSc|tj|}t||||j|jS)aw Calculates `element in test_elements`, broadcasting over `element` only. The output is always a masked array of the same shape as `element`. See `numpy.isin` for more details. See Also -------- in1d : Flattened version of this function. numpy.isin : Equivalent function for ndarrays. Examples -------- >>> import numpy as np >>> element = np.ma.array([1, 2, 3, 4, 5, 6]) >>> test_elements = [0, 2] >>> np.ma.isin(element, test_elements) masked_array(data=[False, True, False, False, False, False], mask=False, fill_value=True) r6r?)rsr<rrr^)element test_elementsr6r?s rQrrs60jj!G m &ww}}56rScFttj||fdS)a 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. Examples -------- >>> import numpy as np >>> ar1 = np.ma.array([1, 2, 3, 4]) >>> ar2 = np.ma.array([3, 4, 5, 6]) >>> np.ma.union1d(ar1, ar2) masked_array(data=[1, 2, 3, 4, 5, 6], mask=False, fill_value=999999) Nr)r,rsr=)r2r5s rQr-r-s* "..#s$7 88rSc|r$tj|j}nt|}t|}|t ||ddS)a 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 -------- >>> import numpy as np >>> x = np.ma.array([1, 2, 3, 4], mask=[0, 1, 0, 1]) >>> np.ma.setdiff1d(x, [1, 2]) masked_array(data=[3, --], mask=[False, True], fill_value=999999) TrG)rsr<rr,r)r2r5r6s rQr)r) sE*jjo##%SkSk tCD> ??rSTctj|ddt}tj|}|s|j r t d|j ddk(rd}tt|}d|z }|rtddf}n dtdf}|k|j ddkDs|j ddkDrtj}ntj}tj|j|}nSt|d dt }tj|} |s| j r t d|j s| j rW|j |j k(r>tj|| } | t ur | x}x|_x|_} d |_d |_tj&||f|}|j ddkDs|j ddkDrtj}ntj}tjtj&|| f|j|}||j)| |z}|||fS) z_ Private function for the computation of covariance and correlation coefficients. rT)ndminrr_zCannot process masked data.r0r7NiF)rrMr_r)rsr1floatrCrrr^intrrr\float64float32 logical_notastype logical_orrHre _sharedmaskr=r) ryrowvar allow_maskedxmaskrWtup xnm_dtypexnotmaskymask common_masks rQ _covhelperr_,s !$e4A OOA E EIIK677wwqzQ f F v:D T{D!U4[!y 771: 1771:#7 I I>>%(// : !%q 6" :; ; 99;%))+ww!''! mmE59 f,8CCECAGCag$)AM$)AM NNAq64 ( 771: 1771:#7 I I>>"..%"FGNN  V S !!A x  rSc||t|k7r td||rd}nd}t||||\}}}|stj|j ||z }tj |dt}tjdd5tjt|j dt|jd|z } dddtj |j} | Stj||j |z }tj |dt}tjdd5tjt|dt|j jd|z } dddtj |j} | S#1swYxYw#1swY= 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 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 Examples -------- >>> import numpy as np >>> x = np.ma.array([[0, 1], [1, 1]], mask=[0, 1, 0, 1]) >>> y = np.ma.array([[1, 0], [0, 1]], mask=[0, 0, 1, 1]) >>> np.ma.cov(x, y) masked_array( data=[[--, --, --, --], [--, --, --, --], [--, --, --, --], [--, --, --, --]], mask=[[ True, True, True, True], [ True, True, True, True], [ True, True, True, True], [ True, True, True, True]], fill_value=1e+20, dtype=float64) Nzddof must be an integerr0r7rbignore)divideinvalidrZ)rOrr_r\rT less_equalrerrstater?conjrsr1squeeze) rrVrWbiasrXddofr\factr[rrs rQrrgsL DCI-233 | DD&q!V\BQ& vvhjj(+d2}}T1D1 [[( ; F66&a.&1*=>ED F$T*224 M vvh +d2}}T1D1 [[( ; F66&A,qssxxz1(=>ED F$T*224 M F F  F FsAGAGGG$cd}|tjus|tjurtj|tdt ||||} t jt j|}|t jj||z}|S#t$rt jcYSwxYw)ai Return Pearson product-moment correlation coefficients. 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 : _NoValue, optional Has no effect, do not use. .. deprecated:: 1.10.0 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. Because `bias` is deprecated, this argument needs to be treated as keyword only to avoid a warning. ddof : _NoValue, optional Has no effect, do not use. .. deprecated:: 1.10.0 See Also -------- numpy.corrcoef : Equivalent function in top-level NumPy module. cov : Estimate the covariance matrix. Notes ----- This function accepts but discards arguments `bias` and `ddof`. This is for backwards compatibility with previous versions of this function. These arguments had no effect on the return values of the function and can be safely ignored in this and previous versions of numpy. Examples -------- >>> import numpy as np >>> x = np.ma.array([[0, 1], [1, 1]], mask=[0, 1, 0, 1]) >>> np.ma.corrcoef(x) masked_array( data=[[--, --], [--, --]], mask=[[ True, True], [ True, True]], fill_value=1e+20, dtype=float64) z/bias and ddof have no effect and are deprecatedrr )rX) r\rr#r$r%rrssqrtdiagonalrMaskedConstantrouter) rrVrWrirXrjmsgcorrstds rQrrs| >> import numpy as np >>> np.ma.mr_[np.ma.array([1,2,3]), 0, 0, np.ma.array([4,5,6])] masked_array(data=[1, 2, 3, ..., 4, 5, 6], mask=False, fill_value=999999) rzc0tj|dy)Nr0)rurp)rns rQrpzmr_class.__init__Ks""4+rSN)rjr~rkrmrrprzrSrQrr6s$I,rSrc#Kttj|t|jD]\}}|s| |r|dt fyw)a Multidimensional index iterator. Return an iterator yielding pairs of array coordinates and values, skipping elements that are masked. With `compressed=False`, `ma.masked` is yielded as the value of masked elements. This behavior differs from that of `numpy.ndenumerate`, which yields the value of the underlying data array. Notes ----- .. versionadded:: 1.23.0 Parameters ---------- a : array_like An array with (possibly) masked elements. compressed : bool, optional If True (default), masked elements are skipped. See Also -------- numpy.ndenumerate : Equivalent function ignoring any mask. Examples -------- >>> import numpy as np >>> a = np.ma.arange(9).reshape((3, 3)) >>> a[1, 0] = np.ma.masked >>> a[1, 2] = np.ma.masked >>> a[2, 1] = np.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) >>> for index, x in np.ma.ndenumerate(a): ... print(index, x) (0, 0) 0 (0, 1) 1 (0, 2) 2 (1, 1) 4 (2, 0) 6 (2, 2) 8 >>> for index, x in np.ma.ndenumerate(a, compressed=False): ... print(index, x) (0, 0) 0 (0, 1) 1 (0, 2) 2 (1, 0) -- (1, 1) 4 (1, 2) -- (2, 0) 6 (2, 1) -- (2, 2) 8 r0N)zipr\r$rCr*rF)r` compresseditr[s rQr$r$VsO|q)<?+?+?@ DHQ%-   s AAAct|}|tustj|s$tjd|j dz gStj |}t|dkDr|ddgSy)a Find the indices of the first and last unmasked values. Expects a 1-D `MaskedArray`, returns None if all values are masked. Parameters ---------- a : 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 -------- >>> import numpy as np >>> a = np.ma.arange(10) >>> np.ma.flatnotmasked_edges(a) array([0, 9]) >>> 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.flatnotmasked_edges(a) array([3, 8]) >>> a[:] = np.ma.masked >>> print(np.ma.flatnotmasked_edges(a)) None r0r7rN)rBrHr\rr1r flatnonzeror)r`rXunmaskeds rQrrsh\  AF{"&&)xxAFFQJ((~~qb!H 8}qB  rSct|}|jdk(r t|St|}t t j |jt j|g|jztfdt|jDtfdt|jDgS)az 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 -------- >>> import numpy as np >>> 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.notmasked_edges(am) array([0, 6]) r7rZc3bK|]&}|jj(ywri)minrrrrWr s rQrz"notmasked_edges..'GA#a&**T"--/G,/c3bK|]&}|jj(ywri)rrrs rQrz"notmasked_edges..rr) r<rrrCr1r\indicesr^rNr)r`rWrXr s ` @rQr&r&sV  A |qvv{"1%%QA  177#"**aS166\*B CC GqvvG G GqvvG G KKrSc*t|}|turtd|jgSd}g}t j |j D]>\}}tt|}|s|jt|||z||z }@|S)an Find contiguous unmasked data in a masked array. Parameters ---------- a : array_like The input array. Returns ------- slice_list : list A sorted sequence of `slice` objects (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 -------- >>> import numpy as np >>> a = np.ma.arange(10) >>> np.ma.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.flatnotmasked_contiguous(a) [slice(3, 5, None), slice(6, 9, None)] >>> a[:] = np.ma.masked >>> np.ma.flatnotmasked_contiguous(a) [] r0) rBrHrr itertoolsgroupbyrrrOr)r`rXrrrgrs rQrrsT  AF{a !! A F##AGGI.A QL MM%1q5/ * Q  MrSc Bt|}|j}|dkDr td||dk(r t|Sg}|dzdz}ddg}t dd||<t |j |D]-}|||<|jt|t|/|S)a 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, and this is the same as `flatnotmasked_contiguous`. Returns ------- endpoints : list A list of slices (start and end indexes) of unmasked indexes in the array. If the input is 2d and axis is specified, the result is a list of lists. See Also -------- flatnotmasked_edges, flatnotmasked_contiguous, notmasked_edges clump_masked, clump_unmasked Notes ----- Only accepts 2-D arrays at most. Examples -------- >>> import numpy as np >>> a = np.arange(12).reshape((3, 4)) >>> mask = np.zeros_like(a) >>> mask[1:, :-1] = 1; mask[0, 1] = 1; mask[-1, 0] = 0 >>> ma = np.ma.array(a, mask=mask) >>> ma masked_array( data=[[0, --, 2, 3], [--, --, --, 7], [8, --, --, 11]], mask=[[False, True, False, False], [ True, True, True, False], [False, True, True, False]], fill_value=999999) >>> np.array(ma[~ma.mask]) array([ 0, 2, 3, 7, 8, 11]) >>> np.ma.notmasked_contiguous(ma) [slice(0, 1, None), slice(2, 4, None), slice(7, 9, None), slice(11, 12, None)] >>> np.ma.notmasked_contiguous(ma, axis=0) [[slice(0, 1, None), slice(2, 3, None)], [], [slice(0, 1, None)], [slice(0, 3, None)]] >>> np.ma.notmasked_contiguous(ma, axis=1) [[slice(0, 1, None), slice(2, 4, None)], [slice(3, 4, None)], [slice(0, 1, None), slice(3, 4, None)]] rz&Currently limited to at most 2D array.Nr7r0) r<rrrrrr^rrN)r`rWrrotherr rs rQr%r%>sv  A B Av!"JKK |rQw'** F AXNE a&CdD!CI 1775> "?E  .qs}=>? MrSc F|jdkDr|j}|dd|ddz j}|ddz}|drdt|dk(rt d|j gSt d|dg}|j dt|ddd|dddDnDt|dk(rgSt|ddd|dddDcgc]\}}t ||}}}|dr(|jt |d|j |Scc}}w)zv Finds the clumps (groups of data with the same values) for a 1D bool array. Returns a series of slices. r7Nrr0c3:K|]\}}t||ywri)r)rleftrights rQrz_ezclump..s%B!dEe$Bsr) rrrrrrextendrr)r[r rrrs rQ_ezclumprs.  yy1}zz| 8d3Bi  ( ( *C a&1*C Aw s8q=!TYY'( ( 1c!f   B%(Qr!Vc!$Q$i%@B C s8q=I36s5Bq5z3qt!t93M NKD%U4  N N Bx s2w *+ H OsDczt|dt}|turtd|jgSt |S)a 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`. See Also -------- flatnotmasked_edges, flatnotmasked_contiguous, notmasked_edges notmasked_contiguous, clump_masked Examples -------- >>> import numpy as np >>> a = np.ma.masked_array(np.arange(10)) >>> a[[0, 1, 2, 6, 8, 9]] = np.ma.masked >>> np.ma.clump_unmasked(a) [slice(3, 6, None), slice(7, 8, None)] rer0)rrrHrrrr`r[s rQr r s9< 1gv &D v~a !! TE?rScVtj|}|turgSt|S)a 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`. See Also -------- flatnotmasked_edges, flatnotmasked_contiguous, notmasked_edges notmasked_contiguous, clump_unmasked Examples -------- >>> import numpy as np >>> a = np.ma.masked_array(np.arange(10)) >>> a[[0, 1, 2, 6, 8, 9]] = np.ma.masked >>> np.ma.clump_masked(a) [slice(0, 3, None), slice(6, 7, None), slice(8, 10, None)] )rsrBrHrrs rQrrs'< ::a=D v~ D>rScbtj||}t|}|turd||<|S)zD Masked values in the input array result in rows of zeros. r0)r\r.rBrH)rr_vanderrXs rQr.r.s1 ii1oG A NrSc t|}t|}t|}|jdk(rt|t|}nJ|jdk(r0tt |}|t urt||dddf}n t d|dt|}|jdk7r t d|jd|jdk7r t dt|t|}|t ur+|} ||| }tj|| || |||||Stj|||||||S)zE Any masked values in x is propagated in y, and vice-versa. r7rNr0z Expected a 1D or 2D array for y!z expected a 1-d array for weightsz(expected w and y to have the same length) r<rBrrErrHrr^r\r') rrVdegrcondfullwrrXmynot_ms rQr'r' s.  A A Avv{ Awqz " 1 Yq\ " V 2ad8$A:;;} AJ 66Q;>? ? 771: #FG G Awqz " =%Azz!E(AeHc5$3GGzz!QUD!S99rSri)NNF)NNFF)NN)FF)F)NTT)NTFTN)T)NFNF)erm__all__rr#numpyr\r1rr2numpy.lib._function_base_implr3numpy.lib._index_tricks_implr4numpy.lib.array_utilsr5r6r8rsr9r:r;r<r=r>rr?r@rArBrCrDrErFrGrHrIrJrKrRrrNr r!rgrrrrrrrr/r(rr rr+rrrrrfindrstriprrr"rr r rr rrrrr,rr*rrr-r)r_rrrurr#r$rr&rr%rr rr.rur'rzrSrQrs "29L233l": z= F2 2 j-_-$ )/ )?2o.%\ 2 $\ 2 $\ 2 (22 X &">2 X &G$  ) !* - Od..662& 00881   # # ( ( 133968,.Obe[[ePK5\R j7t5%p$"N&"RV rkk0fkk/l#L/d)B"J-#`6:90@D8!v\~t"++D++J`(((@, ,2jB J5p1Kh4nK\ :!H!R RYY..? :F"++bjj00'//BrS