ó 2ÄÈ[c-@`s\dZddlmZmZmZddddddd d d d d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/g-Zdd0lZdd0lZd1d2lm Z d1d3l m Z m Z m Z mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z dd0l!Z"dd4l!m#Z#mZ$dd0l%j j&Z&dd5l'm(Z(dd6l)m*Z*dd7l+m,Z,dd8l-m.Z.d9„Z/d0d:„Z1e2d;„Z3d<„Z4d=e5fd>„ƒYZ6d?e6fd@„ƒYZ7dAe6fdB„ƒYZ8dCe6fdD„ƒYZ9dEe6fdF„ƒYZ:e:dƒZ;e:dƒZ<e:dƒZ=e8d/ƒZ>Z?e8dƒZ@e8d ƒZAe8dƒZBe8d+ƒZCe7dƒZDe7dƒZEdG„ZFdH„ZGe"jGjeG_dI„ZHeHjd0k rUe"jHje"jHjjIdJƒ jJƒdKeH_nd0d0eKdL„ZLd0d0eKeKdM„ZMd0d0eKdN„ZNd0dO„ZOd0dP„ZPdQ„ZQdR„ZRd0dS„ZSd0dT„ZTd0d0dU„ZUeKeKdV„ZVeKdW„ZWeKdX„ZXeKeKdY„ZYeKeKdZ„ZZd[„Z[eKd\„Z\d0e]e]d]„Z^d0e]eKe]d0d^„Z_d0e]e"j`e]e"j`d_„Zad`e.fda„ƒYZbdbebfdc„ƒYZcecƒZddd„Zed0de„Zfdf„Zgd0dg„Zhdh„Zidi„Zjdj„Zkd0dk„Zle jme"jljeljƒel_d0eKd0eKdl„Zne jme"jnjenjƒen_d0S(msË 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 $ i(tdivisiontabsolute_importtprint_functiontapply_along_axistapply_over_axest atleast_1dt atleast_2dt atleast_3dtaveraget clump_maskedtclump_unmaskedt column_stackt compress_colst compress_ndtcompress_rowcolst compress_rowst count_maskedtcorrcoeftcovtdiagflattdottdstacktediff1dtflatnotmasked_contiguoustflatnotmasked_edgesthsplitthstacktisintin1dt intersect1dt mask_colst mask_rowcolst mask_rowst masked_alltmasked_all_liketmediantmr_tnotmasked_contiguoustnotmasked_edgestpolyfitt row_stackt setdiff1dtsetxor1dtstacktuniquetunion1dtvandertvstackNi(tcore(t MaskedArraytMAErrortaddtarraytasarrayt concatenatetfilledtcounttgetmaskt getmaskarraytmake_mask_descrtmaskedt masked_arraytmask_ortnomasktonestsorttzerostgetdatatget_masked_subclassRR(tndarrayR4(tnormalize_axis_index(tnormalize_axis_tuple(t_ureduce(tAxisConcatenatorcC`st|tttfƒS(s6 Is seq a sequence (ndarray, list or tuple)? (t isinstanceREttupletlist(tseq((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyt issequence-scC`st|ƒ}|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]) (R:tsum(tarrtaxistm((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyR5s3 cC`s4ttj||ƒ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(R=tnptemptyR@R;(tshapetdtypeta((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyR!ls/cC`s@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') RW( RTt empty_liketviewR1R@RVR;RWt_mask(RPRX((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyR" s2$t_fromnxfunctioncB`s)eZdZd„Zd„Zd„ZRS(sV 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``). cC`s||_|jƒ|_dS(N(t__name__tgetdoct__doc__(tselftfuncname((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyt__init__îs cC`sctt|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 R_sLNotes ----- The function is applied to both the _data and the _mask, if any.s N(tgetattrRTR]tNonetmatget_object_signaturetjoin(R`tnpfunctdoctsigtlocdoc((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyR^òscO`sdS(N((R`targstparams((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyt__call__ s(R]t __module__R_RbR^Rn(((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyR\Ús  t_fromnxfunction_singlecB`seZdZd„ZRS(s² 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. cO`s¨tt|jƒ}t|tƒra||jƒ||Ž}|t|ƒ||Ž}t|d|ƒS|tj|ƒ||Ž}|t|ƒ||Ž}t|d|ƒSdS(NRS( RcRTR]RJREt __array__R:R=R5(R`txRlRmtfunct_dt_m((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyRns(R]RoR_Rn(((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyRpst_fromnxfunction_seqcB`seZdZd„ZRS(s¶ 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. cO`s‡tt|jƒ}|tg|D]}tj|ƒ^qƒ||Ž}|tg|D]}t|ƒ^qSƒ||Ž}t|d|ƒS(NRS(RcRTR]RKR5R:R=(R`RrRlRmRsRXRtRu((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyRn)s41(R]RoR_Rn(((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyRv#st_fromnxfunction_argscB`seZdZd„ZRS(s™ 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. c O`sätt|jƒ}g}t|ƒ}x<t|ƒdkrbt|dƒrb|j|jdƒƒq'Wg}xZ|D]R}|tj|ƒ||Ž}|t |ƒ||Ž}|jt |d|ƒƒqpWt|ƒdkrà|dS|S(NiRSi( RcRTR]RLtlenRNtappendtpopR5R:R=( R`RlRmRstarraystresRrRtRu((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyRn9s % (R]RoR_Rn(((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyRw0st_fromnxfunction_allargscB`seZdZd„ZRS(s 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. cO`stt|jƒ}g}xT|D]L}|tj|ƒ|}|t|ƒ|}|jt|d|ƒƒqWt|ƒdkr‰|dS|S(NRSii(RcRTR]R5R:RyR=Rx(R`RlRmRsR|RrRtRu((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyRnTs (R]RoR_Rn(((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyR}Is cC`s\d}xO|t|ƒkrWx,t||dƒrI|||||d+qW|d7}q W|S(sFlatten a sequence in place.it__iter__i(Rxthasattr(RMtk((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pytflatten_inplacers cO`s”t|dtdtƒ}|j}t||ƒ}dg|d}tj|dƒ}tt|ƒƒ}|j |ƒt d d ƒ||>> a = ma.arange(24).reshape(2,3,4) >>> a[:,0,1] = ma.masked >>> a[:,1,:] = ma.masked >>> print(a) [[[0 -- 2 3] [-- -- -- --] [8 9 10 11]] [[12 -- 14 15] [-- -- -- --] [20 21 22 23]]] >>> print(ma.apply_over_axes(ma.sum, a, [0,2])) [[[46] [--] [124]]] Tuple axis arguments to ufuncs are equivalent: >>> print(ma.sum(a, axis=(0,2)).reshape((1,-1,1))) [[[46] [--] [124]]] c C`st|ƒ}t|ƒ}|d krQ|j|ƒ}|jj|j|ƒƒ}nmtj|ƒ}t |jjtj tj fƒrŸtj |j|jdƒ}ntj |j|jƒ}|j |j krd|d krätdƒ‚n|jdkrtdƒ‚n|j d|j |kr+tdƒ‚ntj||jdd |j ƒ}|jd|ƒ}n|tk r||j}n|jd|d |ƒ}tj||d |ƒj|ƒ|}|rþ|j |j krôtj||j ƒjƒ}n||fS|Sd S( ss 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 to average `a`. If `None`, averaging is done over 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. If `weights` is complex, the imaginary parts are ignored. 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 and floats smaller than `float64`, or the input data-type, otherwise. If returned, `sum_of_weights` is always `float64`. 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] tf8s;Axis must be specified when shapes of a and weights differ.is81D weights expected when shapes of a and weights differ.is5Length of weights not compatible with specified axis.iÿÿÿÿRQRWN(i(R5R9RdtmeanRWttypeR8RTt asanyarrayt issubclasstintegertbool_t result_typeRVRR‡R¦t broadcast_totswapaxesR?RSROtmultiplyR‚( RXRQtweightstreturnedRRtavgtscltwgtt result_dtype((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyRs<3   !    $ % c C`s¿t|dƒsztjt|dtƒd|d|d|d|ƒ}t|tjƒrsd|jkrst|dt ƒS|Snt |d t d|d|d|ƒ\}}|r·|j |ƒS|Sd S( s: 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. .. versionadded:: 1.10.0 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.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. 5.], mask = False, fill_value = 1e+20) RSRƒRQtouttoverwrite_inputtkeepdimsiR‚RsN( RRTR#RCR†RJRER‡R=R…RHt_mediantreshape(RXRQR¼R½R¾RRtrR€((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyR#jsB  ! c`sqtj|jtjƒr$tj}nd}|rzˆdkr[|jƒ‰ˆjd|ƒq’|jdˆd|ƒ|‰nt|dˆd|ƒ‰ˆdkr§d‰ntˆˆj ƒ‰ˆj ˆdkr!t dƒgˆj }t ddƒ|ˆ>> 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]]) is*compress_rowcols works for 2D arrays only.RQ(R5R‡tNotImplementedErrorR (RrRQ((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyR<s3cC`s7t|ƒ}|jdkr*tdƒ‚nt|dƒS(sì Suppress whole rows of a 2-D array that contain masked values. This is equivalent to ``np.ma.compress_rowcols(a, 0)``, see `extras.compress_rowcols` for details. See Also -------- extras.compress_rowcols is'compress_rows works for 2D arrays only.i(R5R‡RæR(RX((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyRts cC`s7t|ƒ}|jdkr*tdƒ‚nt|dƒS(sï Suppress whole columns of a 2-D array that contain masked values. This is equivalent to ``np.ma.compress_rowcols(a, 1)``, see `extras.compress_rowcols` for details. See Also -------- extras.compress_rowcols is'compress_cols works for 2D arrays only.i(R5R‡RæR(RX((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyR …s cC`s 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=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(RXRQ((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyR –s+cC`s 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=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(RXRQ((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyRÃs+cC`stj|ƒ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(ReR®tflatRdtinsertRyRxR(RPtto_endtto_begintedR{((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyRõs    cC`sotj|d|d|ƒ}t|tƒr\t|ƒ}|djtƒ|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) iÿÿÿÿi(ReR6R,RA(Rîtar2t assume_uniquetaux((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyR*s ! cC`s§|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,ReR6RÒRAR7R†(RîRðRñRòtauxftflagtflag2((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyR*Js    ,c C`sá|s-t|dtƒ\}}t|ƒ}ntj||fƒ}|jddƒ}||}|r{|d|d k}n|d|d k}tj||gfƒ} |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. 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. Notes ----- .. versionadded:: 1.4.0 Rítkindt mergesortiiÿÿÿÿN(R,R†ReR6targsortRx( RîRðRñtinverttrev_idxtartordertsartbool_arRôtindx((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyRes cC`s4tj|ƒ}t||d|d|ƒj|jƒS(s| 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. Notes ----- .. versionadded:: 1.13.0 RñRù(ReR5RRÀRV(telementt test_elementsRñRù((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyRscC`sttj||fddƒƒ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. RQN(R,ReR6Rd(RîRð((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyR-¦s cC`sS|rtj|ƒjƒ}nt|ƒ}t|ƒ}|t||dtdtƒS(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.setdiff1d(x, [1, 2]) masked_array(data = [3 --], mask = [False True], fill_value = 999999) RñRù(ReR5RÐR,RR†(RîRðRñ((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyR)´s   c C`stj|dddtdtƒ}tj|ƒ}| rR|jƒrRtdƒ‚n|jddkrnt}ntt |ƒƒ}d|}|r¥t d ƒd f}nd t d ƒf}|d krÞt j |ƒjtƒ}n t|dtdddtƒ}tj|ƒ}| r-|jƒr-tdƒ‚n|jƒsE|jƒr¨|j|jkr¨t j||ƒ} | tk r¥| }|_|_}t|_t|_q¥q¨ntj||f|ƒ}t j t j||f|ƒƒjtƒ}||jd|ƒ|8}|||fS( s_ Private function for the computation of covariance and correlation coefficients. tndminiR‚RWsCannot process masked data.iiRQN(ReR4R†tfloatR:RâR¦RVtinttboolRŠRdRTt logical_nottastypeR…t logical_orR?R[t _sharedmaskR6R¬( Rrtytrowvart allow_maskedtxmaskRQttuptxnotmasktymaskt common_mask((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyt _covhelperÕs8!     *c C`s|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(sJ 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 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``. .. versionadded:: 1.5 Raises ------ ValueError Raised if some values are missing and `allow_masked` is False. See Also -------- numpy.cov sddof must be an integeriigð?tstrictN( RdRR¦RRTRtTtconjR…tsqueeze( RrR R tbiasR tddofRtfactR¤((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyRs6   +(cC`sºd}|tjk s$|tjk r=tj|tddƒnt||||ƒ\}}}|s¥tj|j|ƒd}t|j|jƒdt ƒ|j ƒ} nAtj||jƒd}t||jjƒdt ƒ|j ƒ} yt j | ƒ} Wnt k r dSX|jƒr;t jt jj| | ƒƒ} nwt| ƒ} t | _|jd|} |rxHt| dƒD]ƒ} xzt| d| ƒD]e}tt|| ||fƒƒjddƒ}t jt jj|ƒƒ| | |f<| || fA;tMAxisConcatenatorcB`s2eZdZeeƒZed„ƒZd„ZRS(s› Translate slice objects to concatenation along an axis. For documentation on usage, see `mr_class`. See Also -------- mr_class cC`s4tt|ƒj|jdtƒ}t|d|jƒS(NR‚RS(tsuperR)tmakematRÇR…R4RS(tclsRPRÇ((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyR+°s!cC`s4t|tƒrtdƒ‚ntt|ƒj|ƒS(NsUnavailable for masked array.(RJtstrR2R*R)t __getitem__(R`tkey((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyR.¹s(R]RoR_t staticmethodR6t classmethodR+R.(((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyR)£s   tmr_classcB`seZdZd„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]) cC`stj|dƒdS(Ni(R)Rb(R`((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyRbÑs(R]RoR_Rb(((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyR2ÁscC`szt|ƒ}|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 ---------- 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 -------- >>> 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( R9R?RTRâR4RÒt flatnonzeroRxRd(RXRRtunmasked((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyRÚs- cC`sât|ƒ}|dks'|jdkr1t|ƒSt|ƒ}ttj|jƒdtj|g|jƒƒ}t gt |jƒD]}||j |ƒj ƒ^qƒt gt |jƒD]}||j |ƒj ƒ^q¹ƒgS(s` 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.notmasked_edges(ma) array([0, 6]) iRSN(R5RdR‡RR:R4RTtindicesRVRKRˆtmint compressedR’(RXRQRRRÛR™((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyR&s*   18cC`s t|ƒ}|tkr+td|jƒgSd}g}xbtj|jƒƒD]K\}}tt|ƒƒ}|sŽ|j t|||ƒƒn||7}qMW|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 `slice` objects (start index, end index). ..versionchanged:: 1.15.0 Now returns an empty list instead of None for a fully masked array 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.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) [] i( R9R?RŠRÒt itertoolstgroupbyRÐRxRLRy(RXRRR™R¤R€tgR¡((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyRDs,  "cC`sÎt|ƒ}|j}|dkr0tdƒ‚n|dksH|dkrRt|ƒSg}|dd}ddg}tddƒ||>> 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)], # column broken into two segments [], # fully masked column [slice(0, 1, None)], [slice(0, 3, None)]] >>> np.ma.notmasked_contiguous(ma, axis=1) [[slice(0, 1, None), slice(2, 4, None)], # row broken into two segments [slice(3, 4, None)], [slice(0, 1, None), slice(3, 4, None)]] is%Currently limited to atmost 2D array.iiN( R5R‡RæRdRRŠRˆRVRyRK(RXRQR—R¤totherRÛR™((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyR%|s>      !cC`sU|jdkr|jƒ}n|d|d Ajƒ}|dd}|drÆt|ƒdkrstd|jƒgStd|dƒg}|jd„t|ddd…|ddd…ƒDƒƒnat|ƒdkrÜgSgt|ddd…|ddd…ƒD]\}}t||ƒ^q}|drQ|jt|d|jƒƒn|S(sv Finds the clumps (groups of data with the same values) for a 1D bool array. Returns a series of slices. iiÿÿÿÿics`s$|]\}}t||ƒVqdS(N(RŠ(t.0tlefttright((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pys ÝsiN( R‡RÐtnonzeroRxRŠRÒtextendtzipRy(RSRÛRÁR=R>((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyt_ezclumpÍs   1K  cC`s<t|dtƒ}|tkr1td|jƒgSt|ƒ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.clump_unmasked(a) [slice(3, 6, None), slice(7, 8, None)] R[i(RcR?RŠRÒRB(RXRS((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyR ês! cC`s)tj|ƒ}|tkrgSt|ƒ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.clump_masked(a) [slice(0, 3, None), slice(6, 7, None), slice(8, 10, None)] (ReR9R?RB(RXRS((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyR s! cC`s;tj||ƒ}t|ƒ}|tk r7d||R R?RRdRVRTR'( RrR tdegtrcondtfulltwRRRtmytnot_m((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyR'Ks.    %      '(oR_t __future__RRRt__all__R8RtR0ReR1R2R3R4R5R6R7R8R9R:R;R<R=R>R?R@RARBRCRDRRtnumpyRTRERätnumpy.core.umathtumathtnumpy.core.multiarrayRFtnumpy.core.numericRGtnumpy.lib.function_baseRHtnumpy.lib.index_tricksRIRNRdRRR!R"RR\RpRvRwR}RRRR/R(RR RR+RRRRRtfindtrstripR…RR#R¿R RRR R RRR,RR*RRR-R)R†RRRRR)R2R$RR&RR%RBR R R.tdoc_noteR'(((s./tmp/pip-build-fiC0ax/numpy/numpy/ma/extras.pyt s¦       Ž   7 4 :7           Q   bRV * 8   - 2 *  !+IY  7 3 8 Q  ' , "