bg> dZddlZddlZddlZddlZddlZddlZddlmZddl Z ddl m cm Z ddlm cmZddlmZddl mZmZmZmZmZmZddl mZddlmZddlmZm Z m!Z!m"Z"m#Z#dd l m$Z$dd l%m&Z&gd Z'e jZ(e(dZ)Gd d e*Z+dZ,dZ-dZ.Gdde/Z0Gdde0Z1dddddddddd Z2dD]6Z3e j4de3e2d e3zd!z<e j5de3e2d"e3zd!z<7e j6e j7e j8e j9e j:e j;e j<gZ=ej>Z?e?@d#e=dd$De?@d%e=d&dDejAZBeB@d'e=dd$DeB@d(e=d&dD[=d)ZCd*ZDd+ZEd,ZFd-ZGd.ZHd/ZId0ZJd1ZKd2ZLd3ZMdd4ZNd5ZOdd6ZPePZQe)ddfd7ZRd8ZSiZTiZUGd9d:ZVGd;d<ZWGd=d>ZXGd?d@ZYGdAdBZZGdCdDZ[GdEdFe[Z\GdGdHe[Z]GdIdJe[Z^e\e j_Z_e\e j`Z`e\e jaZae\e jbZbe\e jcZce\e jdZde\e jeZee\e jfZfe\e jgZge\e jhxZiZhe\eZe\e jjZje\e jkZke\e jlZle\e jmZme\e jnZoe\e jpZpe\e jqdKeZdKZqe\e jrdLeYdKZre\e jsdLeYdKZse\e jtdLeYdKZte\e judKeWdMZue\e jvdKeVdNdLZve\e jwdKeVdNdLZwe\e jxdLeZdLZxe\e jydKeVdOdPZye]e jzZze]e j{Z{e]e j|dQdQZ|e]e j}dKdLZ}e]e j~Z~de~_e]e jZde_e]e jZde_e]e jZde_e]e jZde_e]e jZde_e]e jZe]e jdQdQjZe]e jZejZe]e jZe]e jZe]e jZe]e jZe]e jZe^e jeXddQZe^e jeXddQZe^e jeXddQZe^e jeXddQZe^e jeXddQZe^e jeXddQZdRZdSZdTZdUZeZdVZdWZdXZdYde(fdZZdd[Zd\Zdd]Zd^Ze jfd_Zdd`ZddaZddbZddcZdddZddeZddfZddgZddhZddiZddlZddmZGdndoZedpZdqZeejdrejdsejdtejduvZdwZdxZddyZGdzd{ZGd|d}eZd~ZGddeZdZeZeZGddeZexZZeZddYde)dddYdddf dZeje_dZGdde[Zddde jfdZejje_ddde jfdZejje_ddde jfdZejje_GddZedZedxZZedZeddZedZedZedZedZedZedZee jeeHZedZee jeeGZedZedZedZedZedZedZedZedZedZedZedZedZedZddZddZedZedZe jddddfdZejje_ddZdZddZddZdZdZddZdZddZddZdZdZe jje_dZe jje_ddZe jje_dQde je jfdZeefdZddZddZnenZdZddZdZe-e jjd¦e_eZdÄZe-e jjd¦e_eZdĄZddƄZddȄZddɄZddʄZdd˄Zdd̄Zeddfd΄ZdτZGdЄdѦZ e deddYӦddլ֦Z e deddYӦdd٬֦Z e deddYӦddܬ֦Z e dddܬަZ e dddަZe dddަZe deddYӦddܬ֦Ze deddYӦdd֦Ze deddYӦddܬ֦Ze dddܬަZe deddYӦdd֦Ze deddYӦddܬ֦Ze dddܬަZddZdS(a numpy.ma : a package to handle missing or invalid values. This package was initially written for numarray by Paul F. Dubois at Lawrence Livermore National Laboratory. In 2006, the package was completely rewritten by Pierre Gerard-Marchant (University of Georgia) to make the MaskedArray class a subclass of ndarray, and to improve support of structured arrays. Copyright 1999, 2000, 2001 Regents of the University of California. Released for unlimited redistribution. * Adapted for numpy_core 2005 by Travis Oliphant and (mainly) Paul Dubois. * Subclassing of the base `ndarray` 2006 by Pierre Gerard-Marchant (pgmdevlist_AT_gmail_DOT_com) * Improvements suggested by Reggie Dugard (reggie_AT_merfinllc_DOT_com) .. moduleauthor:: Pierre Gerard-Marchant N)reduce) multiarray)ndarrayamaxamin iscomplexobjbool__NoValue)array)angle) getargspec formatargspeclongunicodebytes) expand_dims)normalize_axis_tuple)MAError MaskErrorMaskType MaskedArrayabsabsoluteaddallallcloseallequalalltruerrr anom anomaliesanyappendarangearccosarccosharcsinarcsinharctanarctan2arctanhargmaxargminargsortaroundr asanyarrayasarray bitwise_and bitwise_or bitwise_xorr ceilchooseclipcommon_fill_valuecompress compressed concatenate conjugateconvolvecopy correlatecoscoshcountcumprodcumsumdefault_fill_valuediagdiagonaldiffdivideempty empty_likeequalexprfabsfilled fix_invalid flatten_maskflatten_structured_arrayfloor floor_dividefmod frombufferfromflex fromfunctiongetdatagetmask getmaskarraygreater greater_equal harden_maskhypotidentityidsindicesinner innerproductisMA isMaskedArrayis_mask is_maskedisarray left_shiftless less_equalloglog10log2 logical_and logical_not logical_or logical_xor make_maskmake_mask_descrmake_mask_nonemask_ormasked masked_array masked_equalmasked_greatermasked_greater_equal masked_insidemasked_invalid masked_lessmasked_less_equalmasked_not_equal masked_objectmasked_outsidemasked_print_optionmasked_singleton masked_values masked_wheremaxmaximummaximum_fill_valuemeanminminimumminimum_fill_valuemodmultiplymvoidndimnegativenomasknonzero not_equalones ones_likeouter outerproductpowerprodproductptpputputmaskravel remainderrepeatreshaperesize right_shiftroundround_set_fill_valueshapesinsinhsize soften_masksometruesortsqrtsqueezestdsubtractsumswapaxestaketantanhtrace transpose true_dividevarwherezeros zeros_likeceZdZdS)MaskedArrayFutureWarningN)__name__ __module__ __qualname__D/opt/cloudlinux/venv/lib64/python3.11/site-packages/numpy/ma/core.pyrrTsDrrcX|jdkrdStjdtddS)a Adjust the axis passed to argsort, warning if necessary Parameters ---------- arr The array which argsort was called on np.ma.argsort has a long-term bug where the default of the axis argument is wrong (gh-8701), which now must be kept for backwards compatibility. Thankfully, this only makes a difference when arrays are 2- or more- dimensional, so we only need a warning then. zIn the future the default for argsort will be axis=-1, not the current None, to match its documentation and np.argsort. Explicitly pass -1 or None to silence this warning. stacklevelN)rwarningswarnr)arrs r_deprecate_argsort_axisrWsE x1}}r   B %  4 4 4 4 trc|dS||Stjdtj|}dtj|z}d|dd|gz|ddzS)z9 Adds a Notes section to an existing docstring. Nz\n\s*?Notes\n\s*?-----z Notes ----- %s r)resplitinspectcleandocjoin) initialdocnote notesplitnotedocs rdoc_noterssz  |2G4DZ4P4PQQI&)9$)?)??G 779RaR=G9,y}< = ==rcZ tt|}n#t$rd}YnwxYw|S)z% Get the signature from obj r)rr TypeError)objsigs rget_object_signaturersB Z__-  Js  ((ceZdZdZdS)rz1 Class for masked array related errors. Nrrr__doc__rrrrr DrrceZdZdZdS)rz) Class for mask related errors. NrrrrrrrrrTy@xDg@xDi?B?sN/As???zN/A) bcfiOSuVU) YMWDhmsmsusnspsfsasNaTzM8[]zm8[c,g|]}|tj fSrnpinf.0ks r rs >>>AAw<>>>rc^g|]*}|ttj tj f+Srcomplexrrrs rrr/QQQaAww001QQQrc,g|]}|tj fSrrrs rrrs ???QA=???rc^g|]*}|ttj tj f+Srr rs rrrr rcj=tfdjD}tj|dSjr/j\}}t |}tj||SS)zR Recursively produce a fill value for `dtype`, calling f on scalar dtypes Nc3hK|],}tjt|V-dSN)rr _recursive_fill_value)rnamedtypers r z(_recursive_fill_value..sP)).uT{A>>??))))))rrr)namestuplerr subdtyperfull)rrvalssubtypersubvals`` rrrs { )))))!K)))))xE***2.. &w22wuf%%%qxxrct|tjr|St|dr|jStj|jS)z4 Convert the argument for *_fill_value into a dtype r) isinstancerrhasattrr/rs r _get_dtype_ofr$sH#rx  ( g  (y}S!!''rcFd}t|}t||S)aN Return the default fill value for the argument object. The default filling value depends on the datatype of the input array or the type of the input scalar: ======== ======== datatype default ======== ======== bool True int 999999 float 1.e20 complex 1.e20+0j object '?' string 'N/A' ======== ======== For structured types, a structured scalar is returned, with each field the default fill value for its type. For subarray types, the fill value is an array of the same size containing the default scalar fill value. Parameters ---------- obj : ndarray, dtype or scalar The array data-type or scalar for which the default fill value is returned. Returns ------- fill_value : scalar The default fill value. Examples -------- >>> np.ma.default_fill_value(1) 999999 >>> np.ma.default_fill_value(np.array([1.1, 2., np.pi])) 1e+20 >>> np.ma.default_fill_value(np.dtype(complex)) (1e+20+0j) c|jdvr(t|jdddSt|jdS)NMmrr)kinddefault_fillergetstrrs r_scalar_fill_valuez.default_fill_value.._scalar_fill_valuesG :  !%%eimS99 9!%%ej#66 6rr$r)rr,rs rrDrDs2Z777 #  E (: ; ;;rcPfd}t|}t||S)Nch |S#t$r}td|dddd}~wwxYw)NzUnsuitable type z for calculating .)KeyErrorr)reextremum extremum_names rr,z0_extremum_fill_value.._scalar_fill_values\ E? "   K5KK=KKK  s 1,1r-)rr3r4r,rs `` r_extremum_fill_valuer5sB #  E (: ; ;;rc.t|tdS)a` Return the maximum value that can be represented by the dtype of an object. This function is useful for calculating a fill value suitable for taking the minimum of an array with a given dtype. Parameters ---------- obj : ndarray, dtype or scalar An object that can be queried for it's numeric type. Returns ------- val : scalar The maximum representable value. Raises ------ TypeError If `obj` isn't a suitable numeric type. See Also -------- maximum_fill_value : The inverse function. set_fill_value : Set the filling value of a masked array. MaskedArray.fill_value : Return current fill value. Examples -------- >>> import numpy.ma as ma >>> a = np.int8() >>> ma.minimum_fill_value(a) 127 >>> a = np.int32() >>> ma.minimum_fill_value(a) 2147483647 An array of numeric data can also be passed. >>> a = np.array([1, 2, 3], dtype=np.int8) >>> ma.minimum_fill_value(a) 127 >>> a = np.array([1, 2, 3], dtype=np.float32) >>> ma.minimum_fill_value(a) inf r)r5 min_fillerr#s rrr+` Z ; ;;rc.t|tdS)ad Return the minimum value that can be represented by the dtype of an object. This function is useful for calculating a fill value suitable for taking the maximum of an array with a given dtype. Parameters ---------- obj : ndarray, dtype or scalar An object that can be queried for it's numeric type. Returns ------- val : scalar The minimum representable value. Raises ------ TypeError If `obj` isn't a suitable numeric type. See Also -------- minimum_fill_value : The inverse function. set_fill_value : Set the filling value of a masked array. MaskedArray.fill_value : Return current fill value. Examples -------- >>> import numpy.ma as ma >>> a = np.int8() >>> ma.maximum_fill_value(a) -128 >>> a = np.int32() >>> ma.maximum_fill_value(a) -2147483648 An array of numeric data can also be passed. >>> a = np.array([1, 2, 3], dtype=np.int8) >>> ma.maximum_fill_value(a) -128 >>> a = np.array([1, 2, 3], dtype=np.float32) >>> ma.maximum_fill_value(a) -inf r)r5 max_fillerr#s rrr^r8rc tj|t|j}g}t ||jD]\}}||}|jr |jd}|j1|tt||Y|tj || t|S)a Create a fill value for a structured dtype. Parameters ---------- fillvalue : scalar or array_like Scalar or array representing the fill value. If it is of shorter length than the number of fields in dt, it will be resized. dt : dtype The structured dtype for which to create the fill value. Returns ------- val : tuple A tuple of values corresponding to the structured fill value. rNr) rrlenrziprr"r_recursive_set_fill_valuer item) fillvaluedt output_valuefvalrcdtypes rr>r>s$ )S]]33ILIrx00EE tD ? (_Q'F < #   &?f&M&M N N O O O O   V < < < A A C C D D D D   rctj|}|t|}n%|jt |t tjfrB tj|d|}n#t$r}d}t|||fz|d}~wwxYwtj |t}tjt|||}n{t |tr|j dvrd}t||z tj|d|}n0#ttf$r}d}t|||fz|d}~wwxYwtj|S) a Private function validating the given `fill_value` for the given dtype. If fill_value is None, it is set to the default corresponding to the dtype. If fill_value is not None, its value is forced to the given dtype. The result is always a 0d array. NFr=rz"Unable to transform %s to dtype %srOSVUz6Cannot set fill value of string with array of dtype %sz(Cannot convert fill_value %s to dtype %s)rrrDrr!rvoidr ValueErrorr0objectr>r+charr OverflowError) fill_valuendtyper2err_msgs r_check_fill_valuerPsXf  F'//  ! j7BG"4 5 5 0 HXjuFKKK  H H H> J+?!?@@aG HJf===J";J"O"O(.000JJ j# & & GFKv,E,ENGGf,-- - GXjuFKKK !:. G G GE:v*> >??QF  G 8J  s0A)) B3B  BDE .EE cZt|tr||dS)a Set the filling value of a, if a is a masked array. This function changes the fill value of the masked array `a` in place. If `a` is not a masked array, the function returns silently, without doing anything. Parameters ---------- a : array_like Input array. fill_value : dtype Filling value. A consistency test is performed to make sure the value is compatible with the dtype of `a`. Returns ------- None Nothing returned by this function. See Also -------- maximum_fill_value : Return the default fill value for a dtype. MaskedArray.fill_value : Return current fill value. MaskedArray.set_fill_value : Equivalent method. Examples -------- >>> import numpy.ma as ma >>> a = np.arange(5) >>> a array([0, 1, 2, 3, 4]) >>> a = ma.masked_where(a < 3, a) >>> a masked_array(data=[--, --, --, 3, 4], mask=[ True, True, True, False, False], fill_value=999999) >>> ma.set_fill_value(a, -999) >>> a masked_array(data=[--, --, --, 3, 4], mask=[ True, True, True, False, False], fill_value=-999) Nothing happens if `a` is not a masked array. >>> a = list(range(5)) >>> a [0, 1, 2, 3, 4] >>> ma.set_fill_value(a, 100) >>> a [0, 1, 2, 3, 4] >>> a = np.arange(5) >>> a array([0, 1, 2, 3, 4]) >>> ma.set_fill_value(a, 100) >>> a array([0, 1, 2, 3, 4]) N)r!rrarMs rrrs0x![!!% $$$ Frc^t|tr|j}nt|}|S)zr Return the filling value of a, if any. Otherwise, returns the default filling value for that type. )r!rrMrD)rSresults rget_fill_valuerVs1 ![!!'#A&& MrcRt|}t|}||kr|SdS)a Return the common filling value of two masked arrays, if any. If ``a.fill_value == b.fill_value``, return the fill value, otherwise return None. Parameters ---------- a, b : MaskedArray The masked arrays for which to compare fill values. Returns ------- fill_value : scalar or None The common fill value, or None. Examples -------- >>> x = np.ma.array([0, 1.], fill_value=3) >>> y = np.ma.array([0, 1.], fill_value=3) >>> np.ma.common_fill_value(x, y) 3.0 N)rV)rSrt1t2s rr7r7+s12   B   B Rxx 4rct|dr||St|tr|St|trt j|dSt j|S)a Return input as an array with masked data replaced by a fill value. If `a` is not a `MaskedArray`, `a` itself is returned. If `a` is a `MaskedArray` and `fill_value` is None, `fill_value` is set to ``a.fill_value``. Parameters ---------- a : MaskedArray or array_like An input object. fill_value : array_like, optional. Can be scalar or non-scalar. If non-scalar, the resulting filled array should be broadcastable over input array. Default is None. Returns ------- a : ndarray The filled array. See Also -------- compressed Examples -------- >>> x = np.ma.array(np.arange(9).reshape(3, 3), mask=[[1, 0, 0], ... [1, 0, 0], ... [0, 0, 0]]) >>> x.filled() array([[999999, 1, 2], [999999, 4, 5], [ 6, 7, 8]]) >>> x.filled(fill_value=333) array([[333, 1, 2], [333, 4, 5], [ 6, 7, 8]]) >>> x.filled(fill_value=np.arange(3)) array([[0, 1, 2], [0, 4, 5], [6, 7, 8]]) rNr)r"rNr!rdictrr rRs rrNrNKsrZq( xx ### Aw   At  x3x{{rcXt|dkr5|d}t|trt|}nWt}nOd|D}|d}t |tst}|ddD]}t ||r|}|jdkrtS|S)z Return the youngest subclass of MaskedArray from a list of (masked) arrays. In case of siblings, the first listed takes over. rrc,g|]}t|Sr)typerrSs rrz'get_masked_subclass..s***a$q''***rNMaskedConstant)r<r!rr^ issubclassr)arraysrrclsarrclsclss rget_masked_subclassrfs 6{{aQi c; ' ' 99DDDD**6***ay$ ,, D!"":  C#t$$  }((( Krc |j}n'#t$rtj|d|}YnwxYw|s|t S|S)aE Return the data of a masked array as an ndarray. Return the data of `a` (if any) as an ndarray if `a` is a ``MaskedArray``, else return `a` as a ndarray or subclass (depending on `subok`) if not. Parameters ---------- a : array_like Input ``MaskedArray``, alternatively a ndarray or a subclass thereof. subok : bool Whether to force the output to be a `pure` ndarray (False) or to return a subclass of ndarray if appropriate (True, default). See Also -------- getmask : Return the mask of a masked array, or nomask. getmaskarray : Return the mask of a masked array, or full array of False. Examples -------- >>> import numpy.ma as ma >>> a = ma.masked_equal([[1,2],[3,4]], 2) >>> a masked_array( data=[[1, --], [3, 4]], mask=[[False, True], [False, False]], fill_value=2) >>> ma.getdata(a) array([[1, 2], [3, 4]]) Equivalently use the ``MaskedArray`` `data` attribute. >>> a.data array([[1, 2], [3, 4]]) Fr=subok)_dataAttributeErrorrr viewr)rSridatas rrXrXseT4w 444xU3334 "yy!!! Ks  !..ct|||d}tjtj|j}|s|S|xj|zc_||j}||j|<|S)aQ Return input with invalid data masked and replaced by a fill value. Invalid data means values of `nan`, `inf`, etc. Parameters ---------- a : array_like Input array, a (subclass of) ndarray. mask : sequence, optional Mask. Must be convertible to an array of booleans with the same shape as `data`. True indicates a masked (i.e. invalid) data. copy : bool, optional Whether to use a copy of `a` (True) or to fix `a` in place (False). Default is True. fill_value : scalar, optional Value used for fixing invalid data. Default is None, in which case the ``a.fill_value`` is used. Returns ------- b : MaskedArray The input array with invalid entries fixed. Notes ----- A copy is performed by default. Examples -------- >>> x = np.ma.array([1., -1, np.nan, np.inf], mask=[1] + [0]*3) >>> x masked_array(data=[--, -1.0, nan, inf], mask=[ True, False, False, False], fill_value=1e+20) >>> np.ma.fix_invalid(x) masked_array(data=[--, -1.0, --, --], mask=[ True, False, True, True], fill_value=1e+20) >>> fixed = np.ma.fix_invalid(x) >>> fixed.data array([ 1.e+00, -1.e+00, 1.e+20, 1.e+20]) >>> x.data array([ 1., -1., nan, inf]) T)r=maskri)rxrrpisfiniterjr!_maskrM)rSror=rMinvalids rrOrOsy` QTD999AnR[1122G ;;==GGwGG\ !AGG Hrct|tp4t|to|otjd|DS)Nc3@K|]}t|tVdSr)r!r+)rrs rrz/is_string_or_list_of_strings..s,::*Q,,::::::r)r!r+listbuiltinsr)vals ris_string_or_list_of_stringsrxsN sC  < T " ";s; \::c::: : :=rceZdZdZdZdZdS)_DomainCheckIntervalz~ Define a valid interval, so that : ``domain_check_interval(a,b)(x) == True`` where ``x < a`` or ``x > b``. c6||kr||}}||_||_dS)z9domain_check_interval(a,b)(x) = true where x < a or y > bN)rSrselfrSrs r__init__z_DomainCheckInterval.__init__&s& q55Qrctjd5tjtj||jtj||jcdddS#1swxYwYdS)Execute the call behavior.ignorerrN)rerrstateumathrqr[rrjrSr}xs r__call__z_DomainCheckInterval.__call__-s[ * * * ; ;#EM!TV$<$<$)Jq$&$9$9;; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;sAA((A,/A,Nrrrrr~rrrrrzrzs<;;;;;rrzceZdZdZdZdZdS) _DomainTanz Define a valid interval for the `tan` function, so that: ``domain_tan(eps) = True`` where ``abs(cos(x)) < eps`` c||_dS)z/domain_tan(eps) = true where abs(cos(x)) < eps)N)eps)r}rs rr~z_DomainTan.__init__>s rctjd5tjtjtj||jcdddS#1swxYwYdSExecutes the call behavior.rrN)rrrrjrr?rrs rrz_DomainTan.__call__Bs [ * * * F F:enUYq\\::DHEE F F F F F F F F F F F F F F F F F Fs>A!!A%(A%Nrrrrrr6sAFFFFFrrc eZdZdZddZdZdS)_DomainSafeDividez- Define a domain for safe division. Nc||_dSr) tolerance)r}rs rr~z_DomainSafeDivide.__init__Ns "rch|j#tjtj|_tj|tj|}}tjd5tj||jztj|kcdddS#1swxYwYdS)Nrr) rrfinfofloattinyr0rrrr|s rrz_DomainSafeDivide.__call__Qs > !Xe__1DNz!}}bjmm1 [ * * * K K>!$$t~59J9JJ K K K K K K K K K K K K K K K K K Ks(2B''B+.B+rrrrrrrHsF #### K K K K KrrceZdZdZdZdZdS)_DomainGreaterz4 DomainGreater(v)(x) is True where x <= v. c||_dS)z'DomainGreater(v)(x) = true where x <= vNcritical_valuer}rs rr~z_DomainGreater.__init__c,rctjd5tj||jcdddS#1swxYwYdSr)rrrrkrrs rrz_DomainGreater.__call__gs [ * * * < <#At':;; < < < < < < < < < < < < < < < < < <=AANrrrrrr]s< ---<<<<| r* tj ||d| n#t$rYnwxYw|t!||} | | _t%|t&r| |n*t%|t&r| || S)rrrNunsafecastingr)rXrrseterrrrYrrrqrZrrwr!r Exceptionrlrfrqr!rr) r}rSrrrdadbrUmambrrs rrz_MaskedBinaryOperation.__call__s" AJJ R []] 5 5 IXx 8 8 8 8TVB4T444V44F 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5AJJ R <<V||$\!__b99 6\\ \!__55AA R((A{   M F??quuww?  &"ha@@@@@     $71$=$=>>   a % % *  & &q ) ) ) ) ; ' ' *  & &q ) ) )s#)A''A+.A+>E E$#E$Nct|}t|}t||j}|jdkr6|d}|t urt|d}d|_|t ur#|j ||}t }n=|j |||}tj ||}|js |rtS|S| |} || _| S)z: Reduce `target` along the given `axis`. rrTr=rr)rfrYrNrrrrrsrrrrorwrlrq) r}targetaxisrtclassrttrmr masked_trs rrz_MaskedBinaryOperation.reduce!s %V,, FOO 64: & & 7b== ! Aad+++ ;;q$''BBBq$e44B"))!T22Bx    GGFOO  rc*t|t|}}|j||}t|}t|}|tur|turt}n>t |}t |}t j||}|js |rtS|turtj ||||j s|S| t||} || _| S)zO Return the function applied to the outer product of a and b. r)rXrrrYrrZrrqrrwrrrrlrfrq) r}rSrrrrrrrmasked_ds rrz_MaskedBinaryOperation.outer?s AJJ R FLLR  QZZ QZZ <>   a % % *  & &q ) ) ) ) ; ' ' *  & &q ) ) )s$AAAAD00 D=<D=rrrs@rrresV( - - - - - -(((((((rr?gz8ggg?rct}|jrg}|jD]S}|j|}t|dkr |d|f}||||d|fTt j|}nY|jrPt|j}||jd||d<t jt|}n|}||kr|}|S)z=Private function allowing recursion in _replace_dtype_fields.Nrrr) _replace_dtype_fields_recursiverfieldsr<r"rrrrur)rprimitive_dtype_recursedescrrfield new_dtypes rrrs.H {K F FDL&E5zzQb 4( LL$q? C CD E E E EHUOO  $U^$$8EN1-??aHU5\\** $ E rcrtj|}tj|}t||S)z Construct a dtype description list from a given dtype. Returns a new dtype object, with all fields and subtypes in the given type recursively replaced with `primitive_dtype`. Arguments are coerced to dtypes first. )rrr)rrs r_replace_dtype_fieldsr#s0 HUOOEh//O *5/ B BBrc,t|tS)a Construct a dtype description list from a given dtype. Returns a new dtype object, with the type of all fields in `ndtype` to a boolean type. Field names are not altered. Parameters ---------- ndtype : dtype The dtype to convert. Returns ------- result : dtype A dtype that looks like `ndtype`, the type of all fields is boolean. Examples -------- >>> import numpy.ma as ma >>> dtype = np.dtype({'names':['foo', 'bar'], ... 'formats':[np.float32, np.int64]}) >>> dtype dtype([('foo', '>> ma.make_mask_descr(dtype) dtype([('foo', '|b1'), ('bar', '|b1')]) >>> ma.make_mask_descr(np.float32) dtype('bool') )rr)rNs rrtrt1s< ! 2 22rc.t|dtS)a Return the mask of a masked array, or nomask. Return the mask of `a` as an ndarray if `a` is a `MaskedArray` and the mask is not `nomask`, else return `nomask`. To guarantee a full array of booleans of the same shape as a, use `getmaskarray`. Parameters ---------- a : array_like Input `MaskedArray` for which the mask is required. See Also -------- getdata : Return the data of a masked array as an ndarray. getmaskarray : Return the mask of a masked array, or full array of False. Examples -------- >>> import numpy.ma as ma >>> a = ma.masked_equal([[1,2],[3,4]], 2) >>> a masked_array( data=[[1, --], [3, 4]], mask=[[False, True], [False, False]], fill_value=2) >>> ma.getmask(a) array([[False, True], [False, False]]) Equivalently use the `MaskedArray` `mask` attribute. >>> a.mask array([[False, True], [False, False]]) Result when mask == `nomask` >>> b = ma.masked_array([[1,2],[3,4]]) >>> b masked_array( data=[[1, 2], [3, 4]], mask=False, fill_value=999999) >>> ma.nomask False >>> ma.getmask(b) == ma.nomask True >>> b.mask == ma.nomask True rq)getattrr)rSs rrYrYRsp 1gv & &&rct|}|tur1ttj|t |dd}|S)ae Return the mask of a masked array, or full boolean array of False. Return the mask of `arr` as an ndarray if `arr` is a `MaskedArray` and the mask is not `nomask`, else return a full boolean array of False of the same shape as `arr`. Parameters ---------- arr : array_like Input `MaskedArray` for which the mask is required. See Also -------- getmask : Return the mask of a masked array, or nomask. getdata : Return the data of a masked array as an ndarray. Examples -------- >>> import numpy.ma as ma >>> a = ma.masked_equal([[1,2],[3,4]], 2) >>> a masked_array( data=[[1, --], [3, 4]], mask=[[False, True], [False, False]], fill_value=2) >>> ma.getmaskarray(a) array([[False, True], [False, False]]) Result when mask == ``nomask`` >>> b = ma.masked_array([[1,2],[3,4]]) >>> b masked_array( data=[[1, 2], [3, 4]], mask=False, fill_value=999999) >>> ma.getmaskarray(b) array([[False, False], [False, False]]) rN)rYrrurrr)rros rrZrZsA^ 3<>> import numpy.ma as ma >>> m = ma.masked_equal([0, 1, 0, 2, 3], 0) >>> m masked_array(data=[--, 1, --, 2, 3], mask=[ True, False, True, False, False], fill_value=0) >>> ma.is_mask(m) False >>> ma.is_mask(m.mask) True Input must be an ndarray (or have similar attributes) for it to be considered a valid mask. >>> m = [False, True, False] >>> ma.is_mask(m) False >>> m = np.array([False, True, False]) >>> m array([False, True, False]) >>> ma.is_mask(m) True Arrays with complex dtypes don't return True. >>> dtype = np.dtype({'names':['monty', 'pithon'], ... 'formats':[bool, bool]}) >>> dtype dtype([('monty', '|b1'), ('pithon', '|b1')]) >>> m = np.array([(True, False), (False, True), (True, False)], ... dtype=dtype) >>> m array([( True, False), (False, True), ( True, False)], dtype=[('monty', '?'), ('pithon', '?')]) >>> ma.is_mask(m) False F)rr^rrkrs rrfrfs9|w|x'' uus  ##cT|jj|stS|S)z- Shrink a mask to nomask if possible )rrr!rrs r _shrink_maskr s% w}QUUWW rFcJ|turtSt|}t|tr7|jjr+|t jkrt j|j |St j t|d||d}|rt|}|S)a Create a boolean mask from an array. Return `m` as a boolean mask, creating a copy if necessary or requested. The function can accept any sequence that is convertible to integers, or ``nomask``. Does not require that contents must be 0s and 1s, values of 0 are interpreted as False, everything else as True. Parameters ---------- m : array_like Potential mask. copy : bool, optional Whether to return a copy of `m` (True) or `m` itself (False). shrink : bool, optional Whether to shrink `m` to ``nomask`` if all its values are False. dtype : dtype, optional Data-type of the output mask. By default, the output mask has a dtype of MaskType (bool). If the dtype is flexible, each field has a boolean dtype. This is ignored when `m` is ``nomask``, in which case ``nomask`` is always returned. Returns ------- result : ndarray A boolean mask derived from `m`. Examples -------- >>> import numpy.ma as ma >>> m = [True, False, True, True] >>> ma.make_mask(m) array([ True, False, True, True]) >>> m = [1, 0, 1, 1] >>> ma.make_mask(m) array([ True, False, True, True]) >>> m = [1, 0, 2, -3] >>> ma.make_mask(m) array([ True, False, True, True]) Effect of the `shrink` parameter. >>> m = np.zeros(4) >>> m array([0., 0., 0., 0.]) >>> ma.make_mask(m) False >>> ma.make_mask(m, shrink=False) array([False, False, False, False]) Using a flexible `dtype`. >>> m = [1, 0, 1, 1] >>> n = [0, 1, 0, 0] >>> arr = [] >>> for man, mouse in zip(m, n): ... arr.append((man, mouse)) >>> arr [(1, 0), (0, 1), (1, 0), (1, 0)] >>> dtype = np.dtype({'names':['man', 'mouse'], ... 'formats':[np.int64, np.int64]}) >>> arr = np.array(arr, dtype=dtype) >>> arr array([(1, 0), (0, 1), (1, 0), (1, 0)], dtype=[('man', '>> ma.make_mask(arr, dtype=dtype) array([(True, False), (False, True), (True, False), (True, False)], dtype=[('man', '|b1'), ('mouse', '|b1')]) rT)r=rri) rrtr!rrrrr rrr rNr)rr=shrinkrrUs rrsrssN F{{  E " "E!W-!'.-Ubh5F5Fwqwe,,,,XfQooDT J J JF &f%% Mrc|tj|t}n#tj|t|}|S)a& Return a boolean mask of the given shape, filled with False. This function returns a boolean ndarray with all entries False, that can be used in common mask manipulations. If a complex dtype is specified, the type of each field is converted to a boolean type. Parameters ---------- newshape : tuple A tuple indicating the shape of the mask. dtype : {None, dtype}, optional If None, use a MaskType instance. Otherwise, use a new datatype with the same fields as `dtype`, converted to boolean types. Returns ------- result : ndarray An ndarray of appropriate shape and dtype, filled with False. See Also -------- make_mask : Create a boolean mask from an array. make_mask_descr : Construct a dtype description list from a given dtype. Examples -------- >>> import numpy.ma as ma >>> ma.make_mask_none((3,)) array([False, False, False]) Defining a more complex dtype. >>> dtype = np.dtype({'names':['foo', 'bar'], ... 'formats':[np.float32, np.int64]}) >>> dtype dtype([('foo', '>> ma.make_mask_none((3,), dtype=dtype) array([(False, False), (False, False), (False, False)], dtype=[('foo', '|b1'), ('bar', '|b1')]) Nr)rrrrt)newshaperrUs rrurulsAV }((333(/%*@*@AAA Mrc|jj}|D]V}||}|jjt|||||4tj|||||WdSr)rr_recursive_mask_orrrq)m1m2newmaskrrcurrent1s rrrsy HNE@@d8 >  + xD74= A A A A  Xr$x ? ? ? ? @@rcX|tus|dur)t|dt}t||||S|tus|dur)t|dt}t||||S||urt |r|St|ddt|dd}}||krt d|d|d|j@tjtj ||j |}t||||Sttj ||||S) a Combine two masks with the ``logical_or`` operator. The result may be a view on `m1` or `m2` if the other is `nomask` (i.e. False). Parameters ---------- m1, m2 : array_like Input masks. copy : bool, optional If copy is False and one of the inputs is `nomask`, return a view of the other input mask. Defaults to False. shrink : bool, optional Whether to shrink the output to `nomask` if all its values are False. Defaults to True. Returns ------- mask : output mask The result masks values that are masked in either `m1` or `m2`. Raises ------ ValueError If `m1` and `m2` have different flexible dtypes. Examples -------- >>> m1 = np.ma.make_mask([0, 1, 1, 0]) >>> m2 = np.ma.make_mask([1, 0, 0, 0]) >>> np.ma.mask_or(m1, m2) array([ True, True, True, False]) Fr)r=rrNzIncompatible dtypes 'z'<>''r=r)rrrrsrfrIrrrI broadcastrrrrq)rrr=rrdtype1dtype2rs rrvrvs9J f "++GX..$vUCCCC f "++GX..$vUCCCC RxxGBKKx GT22GB4N4NVV jVVVVVVLMMM |(2<B//5v>>2r7+++ U%b"--D H H HHrcd}fdtj|}||}tjd|DtS)a& Returns a completely flattened version of the mask, where nested fields are collapsed. Parameters ---------- mask : array_like Input array, which will be interpreted as booleans. Returns ------- flattened_mask : ndarray of bools The flattened input. Examples -------- >>> mask = np.array([0, 0, 1]) >>> np.ma.flatten_mask(mask) array([False, False, True]) >>> mask = np.array([(0, 0), (0, 1)], dtype=[('a', bool), ('b', bool)]) >>> np.ma.flatten_mask(mask) array([False, False, False, True]) >>> mdtype = [('a', bool), ('b', [('ba', bool), ('bb', bool)])] >>> mask = np.array([(0, (0, 0)), (0, (0, 1))], dtype=mdtype) >>> np.ma.flatten_mask(mask) array([False, False, False, False, False, True]) c@jj}|fd|DSS)zCFlatten the mask and returns a (maybe nested) sequence of booleans.Nc:g|]}t|Sr)rP)rrros rrz3flatten_mask.._flatmask..s%@@@Ld,,@@@rrr)romnamess` r _flatmaskzflatten_mask.._flatmasks2!  @@@@@@@ @Krc3K |D](}t|dr|Ed{V$|V)dS#t$r|VYdSwxYw)z.Generates a flattened version of the sequence.__iter__N)r"r)sequenceelement _flatsequences rrz#flatten_mask.._flatsequences # " "7J//",}W5555555555!MMMM  " "    NNNNNN s+2AAcg|]}|Srrr_s rrz flatten_mask..s***1Q***rr)rr0r bool)ror flattenedrs @rrPrPsx@      :d  D iioo..I 8** ***$ 7 7 77rch|tjurind|i}|tur|jdd|i|StS)z:Check whether there are masked values along the given axiskeepdimsrr)rr rr)rorr!rs r_check_mask_axisr"sIr{**RRX0FF 6tx,,T,V,,, Mrct|d}tj||d}|j|j}}|r||krt d|d|dt |dr%t ||j}t|}nt}| |}t||_ |sDt |dr4t|tur|j |_|S) a Mask an array where a condition is met. Return `a` as an array masked where `condition` is True. Any masked values of `a` or `condition` are also masked in the output. Parameters ---------- condition : array_like Masking condition. When `condition` tests floating point values for equality, consider using ``masked_values`` instead. a : array_like Array to mask. copy : bool If True (default) make a copy of `a` in the result. If False modify `a` in place and return a view. Returns ------- result : MaskedArray The result of masking `a` where `condition` is True. See Also -------- masked_values : Mask using floating point equality. masked_equal : Mask where equal to a given value. masked_not_equal : Mask where `not` equal to a given value. masked_less_equal : Mask where less than or equal to a given value. masked_greater_equal : Mask where greater than or equal to a given value. masked_less : Mask where less than a given value. masked_greater : Mask where greater than a given value. masked_inside : Mask inside a given interval. masked_outside : Mask outside a given interval. masked_invalid : Mask invalid values (NaNs or infs). Examples -------- >>> import numpy.ma as ma >>> a = np.arange(4) >>> a array([0, 1, 2, 3]) >>> ma.masked_where(a <= 2, a) masked_array(data=[--, --, --, 3], mask=[ True, True, True, False], fill_value=999999) Mask array `b` conditional on `a`. >>> b = ['a', 'b', 'c', 'd'] >>> ma.masked_where(a == 2, b) masked_array(data=['a', 'b', --, 'd'], mask=[False, False, True, False], fill_value='N/A', dtype='>> c = ma.masked_where(a <= 2, a) >>> c masked_array(data=[--, --, --, 3], mask=[ True, True, True, False], fill_value=999999) >>> c[0] = 99 >>> c masked_array(data=[99, --, --, 3], mask=[False, True, True, False], fill_value=999999) >>> a array([0, 1, 2, 3]) >>> c = ma.masked_where(a <= 2, a, copy=False) >>> c[0] = 99 >>> c masked_array(data=[99, --, --, 3], mask=[False, True, True, False], fill_value=999999) >>> a array([99, 1, 2, 3]) When `condition` or `a` contain masked values. >>> a = np.arange(4) >>> a = ma.masked_where(a == 2, a) >>> a masked_array(data=[0, 1, --, 3], mask=[False, False, True, False], fill_value=999999) >>> b = np.arange(4) >>> b = ma.masked_where(b == 0, b) >>> b masked_array(data=[--, 1, 2, 3], mask=[ True, False, False, False], fill_value=999999) >>> ma.masked_where(a == 3, b) masked_array(data=[--, 1, --, --], mask=[ True, False, True, True], fill_value=999999) FrTrhz value). See Also -------- masked_where : Mask where a condition is met. Examples -------- >>> import numpy.ma as ma >>> a = np.arange(4) >>> a array([0, 1, 2, 3]) >>> ma.masked_greater(a, 2) masked_array(data=[0, 1, 2, --], mask=[False, False, False, True], fill_value=999999) r)rr[rvaluer=s rrzrzs#. 5))14 8 8 88rcBtt||||S)a Mask an array where greater than or equal to a given value. This function is a shortcut to ``masked_where``, with `condition` = (x >= value). See Also -------- masked_where : Mask where a condition is met. Examples -------- >>> import numpy.ma as ma >>> a = np.arange(4) >>> a array([0, 1, 2, 3]) >>> ma.masked_greater_equal(a, 2) masked_array(data=[0, 1, --, --], mask=[False, False, True, True], fill_value=999999) r)rr\r,s rr{r{s#.  a// > > >>rcBtt||||S)a Mask an array where less than a given value. This function is a shortcut to ``masked_where``, with `condition` = (x < value). See Also -------- masked_where : Mask where a condition is met. Examples -------- >>> import numpy.ma as ma >>> a = np.arange(4) >>> a array([0, 1, 2, 3]) >>> ma.masked_less(a, 2) masked_array(data=[--, --, 2, 3], mask=[ True, True, False, False], fill_value=999999) r)rrjr,s rr~r~s!. Q 5 5 55rcBtt||||S)a Mask an array where less than or equal to a given value. This function is a shortcut to ``masked_where``, with `condition` = (x <= value). See Also -------- masked_where : Mask where a condition is met. Examples -------- >>> import numpy.ma as ma >>> a = np.arange(4) >>> a array([0, 1, 2, 3]) >>> ma.masked_less_equal(a, 2) masked_array(data=[--, --, --, 3], mask=[ True, True, True, False], fill_value=999999) r)rrkr,s rrrs#.  1e,,ad ; ; ;;rcBtt||||S)a Mask an array where `not` equal to a given value. This function is a shortcut to ``masked_where``, with `condition` = (x != value). See Also -------- masked_where : Mask where a condition is met. Examples -------- >>> import numpy.ma as ma >>> a = np.arange(4) >>> a array([0, 1, 2, 3]) >>> ma.masked_not_equal(a, 2) masked_array(data=[--, --, 2, --], mask=[ True, True, False, True], fill_value=999999) r)rrr,s rrrs#.  !U++QT : : ::rcTtt||||}||_|S)a Mask an array where equal to a given value. Return a MaskedArray, masked where the data in array `x` are equal to `value`. The fill_value of the returned MaskedArray is set to `value`. For floating point arrays, consider using ``masked_values(x, value)``. See Also -------- masked_where : Mask where a condition is met. masked_values : Mask using floating point equality. Examples -------- >>> import numpy.ma as ma >>> a = np.arange(4) >>> a array([0, 1, 2, 3]) >>> ma.masked_equal(a, 2) masked_array(data=[0, 1, --, 3], mask=[False, False, True, False], fill_value=2) r)rrKrM)rr-r=outputs rryry s-6%5//14 8 8 8FF Mrcr||kr||}}t|}||k||kz}t|||S)a Mask an array inside a given interval. Shortcut to ``masked_where``, where `condition` is True for `x` inside the interval [v1,v2] (v1 <= x <= v2). The boundaries `v1` and `v2` can be given in either order. See Also -------- masked_where : Mask where a condition is met. Notes ----- The array `x` is prefilled with its filling value. Examples -------- >>> import numpy.ma as ma >>> x = [0.31, 1.2, 0.01, 0.2, -0.4, -1.1] >>> ma.masked_inside(x, -0.3, 0.3) masked_array(data=[0.31, 1.2, --, --, -0.4, -1.1], mask=[False, False, True, True, False, False], fill_value=1e+20) The order of `v1` and `v2` doesn't matter. >>> ma.masked_inside(x, 0.3, -0.3) masked_array(data=[0.31, 1.2, --, --, -0.4, -1.1], mask=[False, False, True, True, False, False], fill_value=1e+20) rrNrrv1v2r=xfr's rr|r|@sIB BwwR BrbBh'I  14 0 0 00rcr||kr||}}t|}||k||kz}t|||S)a Mask an array outside a given interval. Shortcut to ``masked_where``, where `condition` is True for `x` outside the interval [v1,v2] (x < v1)|(x > v2). The boundaries `v1` and `v2` can be given in either order. See Also -------- masked_where : Mask where a condition is met. Notes ----- The array `x` is prefilled with its filling value. Examples -------- >>> import numpy.ma as ma >>> x = [0.31, 1.2, 0.01, 0.2, -0.4, -1.1] >>> ma.masked_outside(x, -0.3, 0.3) masked_array(data=[--, --, 0.01, 0.2, --, --], mask=[ True, True, False, False, True, True], fill_value=1e+20) The order of `v1` and `v2` doesn't matter. >>> ma.masked_outside(x, 0.3, -0.3) masked_array(data=[--, --, 0.01, 0.2, --, --], mask=[ True, True, False, False, True, True], fill_value=1e+20) rr5r6s rrrhsIB BwwR BbR"W%I  14 0 0 00rc$t|r"tj|j|}|j}n.tjt j||}t}t|t||}t||||S)a Mask the array `x` where the data are exactly equal to value. This function is similar to `masked_values`, but only suitable for object arrays: for floating point, use `masked_values` instead. Parameters ---------- x : array_like Array to mask value : object Comparison value copy : {True, False}, optional Whether to return a copy of `x`. shrink : {True, False}, optional Whether to collapse a mask full of False to nomask Returns ------- result : MaskedArray The result of masking `x` where equal to `value`. See Also -------- masked_where : Mask where a condition is met. masked_equal : Mask where equal to a given value (integers). masked_values : Mask using floating point equality. Examples -------- >>> import numpy.ma as ma >>> food = np.array(['green_eggs', 'ham'], dtype=object) >>> # don't eat spoiled food >>> eat = ma.masked_object(food, 'green_eggs') >>> eat masked_array(data=[--, 'ham'], mask=[ True, False], fill_value='green_eggs', dtype=object) >>> # plain ol` ham is boring >>> fresh_food = np.array(['cheese', 'ham', 'pineapple'], dtype=object) >>> eat = ma.masked_object(fresh_food, 'green_eggs') >>> eat masked_array(data=['cheese', 'ham', 'pineapple'], mask=False, fill_value='green_eggs', dtype=object) Note that `mask` is set to ``nomask`` if possible. >>> eat masked_array(data=['cheese', 'ham', 'pineapple'], mask=False, fill_value='green_eggs', dtype=object) r$ror=rM) rerrKrjrqrr0rrvrsrx)rr-r=rr'ros rrrstQK// wK 1 u55  49V<<< = =D 4E B B BBrh㈵>:0yE>ct||}tj|jtjrtj||||}nt j||}t||||}|r| |S)a Mask using floating point equality. Return a MaskedArray, masked where the data in array `x` are approximately equal to `value`, determined using `isclose`. The default tolerances for `masked_values` are the same as those for `isclose`. For integer types, exact equality is used, in the same way as `masked_equal`. The fill_value is set to `value` and the mask is set to ``nomask`` if possible. Parameters ---------- x : array_like Array to mask. value : float Masking value. rtol, atol : float, optional Tolerance parameters passed on to `isclose` copy : bool, optional Whether to return a copy of `x`. shrink : bool, optional Whether to collapse a mask full of False to ``nomask``. Returns ------- result : MaskedArray The result of masking `x` where approximately equal to `value`. See Also -------- masked_where : Mask where a condition is met. masked_equal : Mask where equal to a given value (integers). Examples -------- >>> import numpy.ma as ma >>> x = np.array([1, 1.1, 2, 1.1, 3]) >>> ma.masked_values(x, 1.1) masked_array(data=[1.0, --, 2.0, --, 3.0], mask=[False, True, False, True, False], fill_value=1.1) Note that `mask` is set to ``nomask`` if possible. >>> ma.masked_values(x, 2.1) masked_array(data=[1. , 1.1, 2. , 1.1, 3. ], mask=False, fill_value=2.1) Unlike `masked_equal`, `masked_values` can perform approximate equalities. >>> ma.masked_values(x, 2.1, atol=1e-1) masked_array(data=[1.0, 1.1, --, 1.1, 3.0], mask=[False, False, True, False, False], fill_value=2.1) )atolrtolr<) rNr issubdtyperfloatingiscloserrKrx shrink_mask) rr-rAr@r=rxnewrorets rrrsz !U  D }TZ--(z$Dt<<<{4'' t$Te D D DC   Jrctj|dd}ttj|||}|jt urt |j|j|_|S)a Mask an array where invalid values occur (NaNs or infs). This function is a shortcut to ``masked_where``, with `condition` = ~(np.isfinite(a)). Any pre-existing mask is conserved. Only applies to arrays with a dtype where NaNs or infs make sense (i.e. floating point types), but accepts any array_like object. See Also -------- masked_where : Mask where a condition is met. Examples -------- >>> import numpy.ma as ma >>> a = np.arange(5, dtype=float) >>> a[2] = np.NaN >>> a[3] = np.PINF >>> a array([ 0., 1., nan, inf, 4.]) >>> ma.masked_invalid(a) masked_array(data=[0.0, 1.0, --, --, 4.0], mask=[False, False, True, True, False], fill_value=1e+20) FTrhr) rr rrprqrrurr)rSr=ress rr}r} sb6 d+++A Q(!$ 7 7 7C yF"39ci88 Jrc<eZdZdZdZdZdZdZd dZdZ e Z d S) _MaskedPrintOptionzN Handle the string used to represent missing data in a masked array. c"||_d|_dS)z9 Create the masked_print_option object. TN)_display_enabled)r}displays rr~z_MaskedPrintOption.__init__J s    rc|jS)zA Display the string to print for masked values. rMrs rrOz_MaskedPrintOption.displayR }rc||_dS)z= Set the string to print for masked values. NrQ)r}rs r set_displayz_MaskedPrintOption.set_displayY s  rc|jS)z; Is the use of the display value enabled? rNrs renabledz_MaskedPrintOption.enabled` rRrrc||_dS)z7 Set the enabling shrink to `shrink`. NrV)r}rs renablez_MaskedPrintOption.enableg s  rc*t|jSr)r+rMrs rrz_MaskedPrintOption.__str__n s4=!!!rNr) rrrrr~rOrTrWrYr__repr__rrrrKrKD s~ """HHHrrKz--c|jj}|'|D]#}||}||}t|||$ntj|||dS)zg Puts printoptions in result where mask is True. Private function allowing for recursion Nr)rr_recursive_printoptionrr)rUroprintoptrrcurdatacurmasks rr]r]w sm L E  ? ?DTlG4jG "7GX > > > > ? &($//// Frz masked_%(name)s(data = %(data)s, %(nlen)s mask = %(mask)s, %(nlen)s fill_value = %(fill)s) z masked_%(name)s(data = %(data)s, %(nlen)s mask = %(mask)s, %(nlen)s fill_value = %(fill)s, %(nlen)s dtype = %(dtype)s) z masked_%(name)s(data = %(data)s, %(nlen)s mask = %(mask)s, %(nlen)s fill_value = %(fill)s) z masked_%(name)s(data = %(data)s, %(nlen)s mask = %(mask)s, %(nlen)s fill_value = %(fill)s, %(nlen)s dtype = %(dtype)s) )long_stdlong_flx short_std short_flxc|jj}|D]W}||}|jjt|||||4tj|||||XdS)z2 Recursively fill `a` with `fill_value`. Nr)rr_recursive_filledrr)rSrorMrrcurrents rrfrf s GMECCD' =  * gtDz:d3C D D D D Igz$/tDz B B B B B CCrcPfdtj|}|j}|}t |t rrtjfd|jD}|t }tjfdt|D|_ n tjfd|D}t|dkr6t|j}||d<t||_|S)a: Flatten a structured array. The data type of the output is chosen such that it can represent all of the (nested) fields. Parameters ---------- a : structured array Returns ------- output : masked array or ndarray A flattened masked array if the input is a masked array, otherwise a standard ndarray. Examples -------- >>> ndtype = [('a', int), ('b', float)] >>> a = np.array([(1, 1), (2, 2)], dtype=ndtype) >>> np.ma.flatten_structured_array(a) array([[1., 1.], [2., 2.]]) c3|Kt|D](}t|dr|Ed{V$|V)dS)z; Flattens a compound of nested iterables. rN)iterr")iterableelmflatten_sequences rrmz2flatten_structured_array..flatten_sequence sk >>  CsJ'' ++C0000000000   rcdg|],}t|-Srrr?rrrms rrz,flatten_structured_array.. s5KKKa..qvvxx8899KKKrcdg|],}t|-Srrorps rrz,flatten_structured_array.. sE888"#$$4$4QVVXX$>$>??888rcdg|],}t|-Srrorps rrz,flatten_structured_array.. s5EEEa..qvvxx8899EEErrr)rr/rrr!rr rjrlrZrqr<rur)rSinishapeoutrrms @rrQrQ s96      aAwH  A![!!GhKKKK17KKKLLhh{##H8888'3A88899 hEEEE1EEEFF 8}}q ?? **84455 Jrcfd}ttdpttd}| |j|_|_|S)a Return a class method wrapper around a basic array method. Creates a class method which returns a masked array, where the new ``_data`` array is the output of the corresponding basic method called on the original ``_data``. If `onmask` is True, the new mask is the output of the method called on the initial mask. Otherwise, the new mask is just a reference to the initial mask. Parameters ---------- funcname : str Name of the function to apply on data. onmask : bool Whether the mask must be processed also (True) or left alone (False). Default is True. Make available as `_onmask` attribute. Returns ------- method : instancemethod Class method wrapper of the specified basic array method. c2t|j|i|}|t|}|||j}s||n$|turt||i||_|Sr)rrjrlr^rrq __setmask__r)r}rparamsrUrofuncnameonmasks rwrapped_methodz$_arraymethod..wrapped_method s.X..???T$ZZ((D!!!z D   t $ $ $ $   27422DCFCCFL rN)rrrrr)ryrzr{methdocs`` r _arraymethodr} sd6      gx..M'"h2M2MG!(&N rc0eZdZdZdZdZdZdZdZdS)MaskedIteratora Flat iterator object to iterate over masked arrays. A `MaskedIterator` iterator is returned by ``x.flat`` for any masked array `x`. It allows iterating over the array as if it were a 1-D array, either in a for-loop or by calling its `next` method. Iteration is done in C-contiguous style, with the last index varying the fastest. The iterator can also be indexed using basic slicing or advanced indexing. See Also -------- MaskedArray.flat : Return a flat iterator over an array. MaskedArray.flatten : Returns a flattened copy of an array. Notes ----- `MaskedIterator` is not exported by the `ma` module. Instead of instantiating a `MaskedIterator` directly, use `MaskedArray.flat`. Examples -------- >>> x = np.ma.array(arange(6).reshape(2, 3)) >>> fl = x.flat >>> type(fl) >>> for item in fl: ... print(item) ... 0 1 2 3 4 5 Extracting more than a single element b indexing the `MaskedIterator` returns a masked array: >>> fl[2:4] masked_array(data = [2 3], mask = False, fill_value = 999999) c||_|jj|_|jt ur d|_dS|jj|_dSr)rrjflatdataiterrqrmaskiter)r}rs rr~zMaskedIterator.__init__M s;  8v   DMMMHMDMMMrc|Srrrs rrzMaskedIterator.__iter__V  rc|j|t|j}|j|j|}t |tr|j|_||_ n?t |tj rt|||jj S|rtS|S)Nrohardmask)r __getitem__rlr^rrr!rrrqrrHr _hardmaskrw)r}indxrUrqs rrzMaskedIterator.__getitem__Y s**40055d47mmDD = $M--d33E%)) $l $ E27++ V%$':KLLLL   rctt||j|<|jt||j|<dSdSr)rXrrrZ)r}indexr-s r __setitem__zMaskedIterator.__setitem__h s>&u~~ e = $#/#6#6DM%  % $rct|j}|jSt|j}t|tjrt |||jjS|rtS|S)aT Return the next value, or raise StopIteration. Examples -------- >>> x = np.ma.array([3, 2], mask=[0, 1]) >>> fl = x.flat >>> next(fl) 3 >>> next(fl) masked >>> next(fl) Traceback (most recent call last): ... StopIteration Nr) nextrrr!rrHrrrrw)r}rrs r__next__zMaskedIterator.__next__m sj$    = $T]##A!RW%% QQ1BCCCC  rN) rrrrr~rrrrrrrrr sj--^***   777 rrc eZdZdZdZeZdZeZ dZ dZ dedddddddddf d Z d Z d Zdd Zdd ZdZejdddZefdZejfdZefdZejfdZddZeZedZejdZedZejdZdZdZedZdZ edZ!d Z"ed!Z#d"Z$ee$#Z%ee$#Z&ed$Z'e'jd%Z'ed&Z(e(jdd'Z(e(j)Z*e(j+Z,dd(Z-d)Z.dd*Z/d+Z0d,Z1d-Z2d.Z3d/Z4d0Z5d1Z6d2Z7d3Z8d4Z9d5Z:d6Z;d7Zd:Z?d;Z@d<ZAd=ZBd>ZCd?ZDd@ZEdAZFdBZGdCZHdDZIdEZJdFZKdGZLdHZMdIZNdJZOdKZPedLZQeQj)ZRedMZSeSj)ZTdejUfdNZVddPZWdQZXddRZYddTZZdUZ[dVZ\ddejUfdWZ]ddejUfdXZ^dYZ_dfd[ Z`ej`je`_dd\ZadddejUfd]Zbdd^ZcdddejUfd_ZdedZedd`ZfdddejUffda ZgddbZhddddejUffdc Ziejijei_ddddejUfddZjddeZkejUddddfdfZldejUdgdhZmdejUdgdiZn ddkZodddejUfdlZpdddejUfdmZqddnZrfdoZsfdpZtddqZuevdrZwevdsZxevdtZyevduZzevdvZ{evdwZ|edx#Z}evdyZ~ddzZdd{Zdd|ZddZdZeZfdZfdZdZddZxZS)raz An array class with possibly masked values. Masked values of True exclude the corresponding element from any computation. Construction:: x = MaskedArray(data, mask=nomask, dtype=None, copy=False, subok=True, ndmin=0, fill_value=None, keep_mask=True, hard_mask=None, shrink=True, order=None) Parameters ---------- data : array_like Input data. mask : sequence, optional Mask. Must be convertible to an array of booleans with the same shape as `data`. True indicates a masked (i.e. invalid) data. dtype : dtype, optional Data type of the output. If `dtype` is None, the type of the data argument (``data.dtype``) is used. If `dtype` is not None and different from ``data.dtype``, a copy is performed. copy : bool, optional Whether to copy the input data (True), or to use a reference instead. Default is False. subok : bool, optional Whether to return a subclass of `MaskedArray` if possible (True) or a plain `MaskedArray`. Default is True. ndmin : int, optional Minimum number of dimensions. Default is 0. fill_value : scalar, optional Value used to fill in the masked values when necessary. If None, a default based on the data-type is used. keep_mask : bool, optional Whether to combine `mask` with the mask of the input data, if any (True), or to use only `mask` for the output (False). Default is True. hard_mask : bool, optional Whether to use a hard mask or not. With a hard mask, masked values cannot be unmasked. Default is False. shrink : bool, optional Whether to force compression of an empty mask. Default is True. order : {'C', 'F', 'A'}, optional Specify the order of the array. If order is 'C', then the array will be in C-contiguous order (last-index varies the fastest). If order is 'F', then the returned array will be in Fortran-contiguous order (first-index varies the fastest). If order is 'A' (default), then the returned array may be in any order (either C-, Fortran-contiguous, or even discontiguous), unless a copy is required, in which case it will be C-contiguous. Examples -------- The ``mask`` can be initialized with an array of boolean values with the same shape as ``data``. >>> data = np.arange(6).reshape((2, 3)) >>> np.ma.MaskedArray(data, mask=[[False, True, False], ... [False, False, True]]) masked_array( data=[[0, --, 2], [3, 4, --]], mask=[[False, True, False], [False, False, True]], fill_value=999999) Alternatively, the ``mask`` can be initialized to homogeneous boolean array with the same shape as ``data`` by passing in a scalar boolean value: >>> np.ma.MaskedArray(data, mask=False) masked_array( data=[[0, 1, 2], [3, 4, 5]], mask=[[False, False, False], [False, False, False]], fill_value=999999) >>> np.ma.MaskedArray(data, mask=True) masked_array( data=[[--, --, --], [--, --, --]], mask=[[ True, True, True], [ True, True, True]], fill_value=999999, dtype=int64) .. note:: The recommended practice for initializing ``mask`` with a scalar boolean value is to use ``True``/``False`` rather than ``np.True_``/``np.False_``. The reason is :attr:`nomask` is represented internally as ``np.False_``. >>> np.False_ is np.ma.nomask True FdiNTrc Ltj|||| d|t|dt} t |t r|jjkrd}t ||r:|r8t |ts#tj t|ntj |t|dr!t |ts |j _ tj |tur'|s2| rt_ ntjj_ nt |t t"frq tjfd|D}n#t$t&f$r t}YnwxYwt(kr"|r|_ d_n| _|rZj _ t1|tur&|j j|jkr|j|j _n|d}|dur't(krtjj}nv|dur't(krtjj}nK tj|| }n2#t&$r%tjfd |D}YnwxYw|jjkrhj|j}} |d krtj|j}n7|| krtj|j}nd }t;|| |fzd}j tur|_ | _n[|s|_ | _nIj jfd j |ntj|j _ d_|t|dd}|tA|j _!| t|dd_"n| _"| _#S)z Create a new masked array from scratch. Notes ----- A masked array can also be created by taking a .view(MaskedArray). T)rr=orderrindmin _baseclassrqrc`g|]*}ttj|j+S)r)rZrr/r)rrrjs rrz'MaskedArray.__new__..* sB(((&bmAU[&I&I&IJJ(((rFNrFcPg|]"}t|gtz#Srrr<rrmdtypes rrz'MaskedArray.__new__..S .$L$L$L!UA3V+<%=%=$L$L$Lrrz?Mask and data not compatible: data size is %i, mask size is %i.c|jjD]0}||||}}|jj ||+||z}1dS)z'do a|=b on each field of a, recursivelyNr)rSrrafbf _recursive_ors rrz*MaskedArray.__new__.._recursive_ork s[() --,-dGQtWR#%8>#=$1M"b$9$9$9$9$&"HBB --r _fill_valuer)$rr rr^r!rrr`rrlr"rqrtrrrrrurIrrr! _sharedmaskr=rYrrrrrrrqrPrrr)rermrorr=rirrM keep_mask hard_maskrrrndnmmsgrjrrs @@@r__new__zMaskedArray.__new__ sU$D???T<e== dK ( ( djEK.G.GD dC  -U -:dN3S3S -LT 33EEL,,E 4 ! ! %*T7*C*C %*EK!-- 6>>! :F"(EKK#%(5;f"E"E"EEKKD5$-00 :"8(((("&(((/5777DD#I."""!DDD"h&&DHHJJ&"&EK(-E%(,H! :"'+"2"2"4"4EKt}}F22  :+tz99/3zDJ,|t||( 2 2wu{&9996X#5#5x 6:::28Dt6BBBDD 2228$L$L$L$Lt$L$L$L*0222DDD2zU[((!J R779T5;77DD2XX:dEK88DD-C#C2r(N333{f$$" (,H!! ."&EK,0E%%{(4-----& ek48888&(mD%+&F&F (-E%   }d;;J  ! 1*ek J JE   %dK??EOO'EO% s$""FF F J++,KKc t|trt|}nt}i}|t |di|t |dit|t s$|t |dit t |ddt |ddt |ddt |d dt |d ||| }|j||j|dS) z9 Copies some attributes of obj to self. _optinfo _basedict__dict__rNrFr_isfieldr)rrrrrrr)r!rr^updaterrr[r)r}rrr_dicts rrzMaskedArray._update_from s0 c7 # # !cJJ JZ44555["55666#{++ : OOGCR88 9 9 9mT!B!B&sK??!(mU!C!C%c:u== '\: F F&' ))) U### X&&&rc\||t|tr|jjt |}nt |}|tur|jdd|jddkrc|j|jkr|j}nt|j}|j j rd}n|j j rd}nd}| ||}n|}nt}||_|jturA |j|j_n.#t"$rt|_Ynt$t&f$rYnwxYw|j!t+|j|j|_dS|jjt+d|j|_dSdS)z. Finalizes the masked array. NrmrCFK)rr!rrrrZrYr__array_interface__rtflags c_contiguous f_contiguousastyperlrqrrIrrkrrP)r}rrq _mask_dtypers r__array_finalize__zMaskedArray.__array_finalize__ s #8 c7 # #' y*$S)) V##(?(G(J/7:););:**"'+KK"1$*"="=K:* EEZ, EEE [%88 E :V # # #':    $ $ $# ~.       '01A4:NND    Z  )0tzBBD   * )sD..EEEc4||ur|}n7|t|}|||V|j|_|\}}}|d|j}t td|D}t |d} | tj dd5t| |d} dddn #1swxYwY| rl t|d} n/#t$rt|} Ynt $r |j} YnwxYwtj|| | |t&ur| }n|| z}||ur|jdkr |rt*S||_d |_|S) zr Special hook for ufuncs. Wraps the numpy array and sets the mask according to context. Nc,g|]}t|SrrZ)rargs rrz.MaskedArray.__array_wrap__.. s I I Isc!2!2 I I IrrrTrrrF)rlr^rrqr=ninrrvrr*rrrNr!rrr1rMrrrrwr) r}rcontextrUfuncrout_i input_argsrrrrMs r__array_wrap__zMaskedArray.__array_wrap__ s  $;;FFXXd4jj))F    % % %  !<,,..FL ' D$itxiJw I Ij I I IJJA!%%dD11F![(CCC::vvz2D99A:::::::::::::::5577$5%0%6r%: $777%0%6 #555%)_ 5Ifj::::F{{UT!!flb&8&8Q&8   %*" s*C''C+.C+DE4EEc|-|tj|}ntj||}n|i t|trtj||}d}ntj||}n;#t$rtj||}YnwxYwtj|||}t |t ur|j|_t|dd| |nd|_n||_ |S)a3 Return a view of the MaskedArray data. Parameters ---------- dtype : data-type or ndarray sub-class, optional Data-type descriptor of the returned view, e.g., float32 or int16. The default, None, results in the view having the same data-type as `a`. As with ``ndarray.view``, dtype can also be specified as an ndarray sub-class, which then specifies the type of the returned object (this is equivalent to setting the ``type`` parameter). type : Python type, optional Type of the returned view, either ndarray or a subclass. The default None results in type preservation. fill_value : scalar, optional The value to use for invalid entries (None by default). If None, then this argument is inferred from the passed `dtype`, or in its absence the original array, as discussed in the notes below. See Also -------- numpy.ndarray.view : Equivalent method on ndarray object. Notes ----- ``a.view()`` is used two different ways: ``a.view(some_dtype)`` or ``a.view(dtype=some_dtype)`` constructs a view of the array's memory with a different data-type. This can cause a reinterpretation of the bytes of memory. ``a.view(ndarray_subclass)`` or ``a.view(type=ndarray_subclass)`` just returns an instance of `ndarray_subclass` that looks at the same array (same shape, dtype, etc.) This does not cause a reinterpretation of the memory. If `fill_value` is not specified, but `dtype` is specified (and is not an ndarray sub-class), the `fill_value` of the MaskedArray will be reset. If neither `fill_value` nor `dtype` are specified (or if `dtype` is an ndarray sub-class), then the fill value is preserved. Finally, if `fill_value` is specified, but `dtype` is not, the fill value is set to the specified value. For ``a.view(some_dtype)``, if ``some_dtype`` has a different number of bytes per entry than the previous dtype (for example, converting a regular array to a structured array), then the behavior of the view cannot be predicted just from the superficial appearance of ``a`` (shown by ``print(a)``). It also depends on exactly how ``a`` is stored in memory. Therefore if ``a`` is C-ordered versus fortran-ordered, versus defined as a slice or transpose, etc., the view may give different results. Nr) rrlrarrYrrqrrrM)r}rr^rMr3s rrlzMaskedArray.view7 s p =| d++ dD11 \ 3eW--7$\$66F EE$\$66F 3 3 3 dE22 3\$t44F 6??& ( (!<,,..FL 6=$ / / ;!=)-F&&$.! sAA66BBc|j|}|j}d}d}|tur||}||}n8t}||j|}||t||}|rt |t jrt|||jS|j j t j ur8t |t j r|tur|rt|dS|S|rtS|S|t|}||t#|r|j|j||_t |jt j st'd|jjdkr|j|jjdks(t/jd |d |jdd d |jjddd|_d|_|tur!t7||j|_d|_|S)zi x.__getitem__(y) <==> x[y] Return the item described by i, as a masked array. c8t|tj Sr)r!rrrs r _is_scalarz+MaskedArray.__getitem__.._is_scalar s!!RZ000 0rct|tjsdS|jjtjur|j|jurdSn$t |jtjkrdSdS)z Return whether `elem` is a scalar result of indexing `arr`, or None if undecidable without promoting nomask to a full mask TFN)r!rrrr^object_r)relems r_scalar_heuristicz2MaskedArray.__getitem__.._scalar_heuristic sn dBJ// t2:--9DJ.. 4/c&'*===u4rNrTrozInternal NumPy error.rz&Upon accessing multidimensional field zi, need to keep dimensionality of fill_value at 0. Discarding heterogeneous fill_value and setting all to r0rrr)rmrqrrZr!rrHrrrr^rrrwrrlrrxr RuntimeErrorrrrrrrrrrr)r}rdoutrqrrmoutscalar_expecteds rrzMaskedArray.__getitem__ sy  1 1 1   .   ;D(j..OOD// 4@@O&#-*\$-?-?-E"F"F A ($(( Tt~FFFF*/RZ//T2:..0f$$ &t$7777K !MK99T$ZZ((D   d # # #+D11 %#/'+'7'=D$&d&6 CCD*+BCCC',q00 $ 0 $ 0 5a 8!9:=#%%.$M!C#'!C!C+/*:1*= !C!C!C ,- ....,0+;+@1+E+M+MST+M+U+U( $ 6!!$T4:66 #'  rr)overrrc|turtd|j}|j}t |t rC|||<|t ur!t|j|j x|_}t|||<dS|j }|tur\|t urt|j|x}|_|j )tdgt|j z||<nd||<dSt|d|}t|}|j .|t ur%tdgt|j z}|t ur0|||<|t ur!t|j|x}|_|||<n|js@t |t r t |t s |||j<n|||<|||<nt%|dr-|j t&kr|t)j|z}|||<nv|j d}t-|t/|||d} |j|} | jd krt3j| ||  n | t ur|} | ||<| ||<dS) z x.__setitem__(i, y) <==> x[i]=y Set item described by index. If value is masked, masks those locations. z Cannot alter the masked element.NTrjFrz,Flexible 'hard' masks are not yet supported.rrr)rwrrjrqr!r+rrurrrYrrr<rrrxrmr"rrrpNotImplementedErrorrvrrr) r}rr-rjrq_dtypedvalmvalrOmindxdindxs rrzMaskedArray.__setitem__ s 6>>>?? ?   dC  E$K%3DJ %K%KK U!%..E$K F F??%3DJ%G%GG |'#TFS->->$>??d "d Fugu--u~~ < #%3v|#4#4455D F??E$K6!!%3DJ%G%GG "d  4.. #"5,77 ##'di  "d "d T7 # # x)?)?%+E222DE$KK|'H)'222E$KD999EJt$EzA~~ %eV44444&E$KE$Krc*tjSr)rrr}rs rrzMaskedArray.dtypeY ww}rcVttt|j|||jt ur^|jt|t|_ |j |j_ dS#ttf$rYdSwxYwdSr) rrr^r__set__rqrrlrtrrrkr)r}rrs rrzMaskedArray.dtype] s k4::&&,44T5AAA :V # #)?)?IIDJ #':    "I.     $ #s>BB&%B&c*tjSr)rrrs rrzMaskedArray.shapei rrcttt|j||t |t ur|j|j_dSdSr)rrr^rrrYrrq)r}rrs rrzMaskedArray.shapem sY k4::&&,44T5AAA 4== & &#zDJ    ' &rc|j}|j}|turd}|tur'|turdSt |j|x}|_|jP|jr||z}nt|tttj tj fr||d<nL||_nC|jtj|d}|jsm|jjdkrGtjt%|gt)z}na|}nK tj||}n2#t,$r%tjfd |D}YnwxYw|jr!|jD]}||xx||zcc<n?t|tttj tj fr||d<n||_|jr |j|_dS) z Set the mask. TN.FrrrrFcPg|]"}t|gtz#Srrrs rrz+MaskedArray.__setmask__.. rr)rrqrwrrurrrr!intrrr numberrr rr(rr?r<rr)r}ror=idtype current_masknrs @rrwzMaskedArray.__setmask__u s1 z 6>>D 6 ! !v~~(6tz6(J(J JL4: < ~ )$ D3rx"CDD )$( S!!%) !!"'F8Du---D9 2:?c))8E499;;-#f++*E$F$F*0222DD ;;v..DD28Dt6BBBDD 2228$L$L$L$Lt$L$L$L*0222DDD2~ )//A OOOtAw.OOOO/ D3rx"CDD )$( S!!%) !   ,!%L s4E ,E;:E;c4|jS)z Current mask. )rqrlrs rrozMaskedArray.mask sz   rc0||dSr)rw)r}r-s rrozMaskedArray.mask s rc|jt}|jj|St jt|dS)a Get or set the mask of the array if it has no named fields. For structured arrays, returns a ndarray of booleans where entries are ``True`` if **all** the fields are masked, ``False`` otherwise: >>> x = np.ma.array([(1, 1), (2, 2), (3, 3), (4, 4), (5, 5)], ... mask=[(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)], ... dtype=[('a', int), ('b', int)]) >>> x.recordmask array([False, False, True, False, False]) Nrr)rqrlrrrrrrQ)r}rqs r recordmaskzMaskedArray.recordmask sE (( ;  $Lv.u55B????rc td)Nz*Coming soon: setting the mask per records!r)r}ros rrzMaskedArray.recordmask s!"NOOOrcd|_|S)a Force the mask to hard, preventing unmasking by assignment. Whether the mask of a masked array is hard or soft is determined by its `~ma.MaskedArray.hardmask` property. `harden_mask` sets `~ma.MaskedArray.hardmask` to ``True`` (and returns the modified self). See Also -------- ma.MaskedArray.hardmask ma.MaskedArray.soften_mask Trrs rr]zMaskedArray.harden_mask s rcd|_|S)a Force the mask to soft (default), allowing unmasking by assignment. Whether the mask of a masked array is hard or soft is determined by its `~ma.MaskedArray.hardmask` property. `soften_mask` sets `~ma.MaskedArray.hardmask` to ``False`` (and returns the modified self). See Also -------- ma.MaskedArray.hardmask ma.MaskedArray.harden_mask Frrs rrzMaskedArray.soften_mask s rc|jS)a Specifies whether values can be unmasked through assignments. By default, assigning definite values to masked array entries will unmask them. When `hardmask` is ``True``, the mask will not change through assignments. See Also -------- ma.MaskedArray.harden_mask ma.MaskedArray.soften_mask Examples -------- >>> x = np.arange(10) >>> m = np.ma.masked_array(x, x>5) >>> assert not m.hardmask Since `m` has a soft mask, assigning an element value unmasks that element: >>> m[8] = 42 >>> m masked_array(data=[0, 1, 2, 3, 4, 5, --, --, 42, --], mask=[False, False, False, False, False, False, True, True, False, True], fill_value=999999) After hardening, the mask is not affected by assignments: >>> hardened = np.ma.harden_mask(m) >>> assert m.hardmask and hardened is m >>> m[:] = 23 >>> m masked_array(data=[23, 23, 23, 23, 23, 23, --, --, 23, --], mask=[False, False, False, False, False, False, True, True, False, True], fill_value=999999) rrs rrzMaskedArray.hardmasks T~rc^|jr%|j|_d|_|S)aY Copy the mask and set the `sharedmask` flag to ``False``. Whether the mask is shared between masked arrays can be seen from the `sharedmask` property. `unshare_mask` ensures the mask is not shared. A copy of the mask is only made if it was shared. See Also -------- sharedmask F)rrqr=rs r unshare_maskzMaskedArray.unshare_mask1s/   %**DJ$D  rc|jS)z' Share status of the mask (read-only). )rrs r sharedmaskzMaskedArray.sharedmaskCs rc8t|j|_|S)a Reduce a mask to nomask when possible. Parameters ---------- None Returns ------- None Examples -------- >>> x = np.ma.array([[1,2 ], [3, 4]], mask=[0]*4) >>> x.mask array([[False, False], [False, False]]) >>> x.shrink_mask() masked_array( data=[[1, 2], [3, 4]], mask=False, fill_value=999999) >>> x.mask False )rrqrs rrEzMaskedArray.shrink_maskHs8"$*--  rc|jS)z+ Class of the underlying data (read-only). )rrs r baseclasszMaskedArray.baseclassgs rc6tj||jS)a Returns the underlying data, as a view of the masked array. If the underlying data is a subclass of :class:`numpy.ndarray`, it is returned as such. >>> x = np.ma.array(np.matrix([[1, 2], [3, 4]]), mask=[[0, 1], [1, 0]]) >>> x.data matrix([[1, 2], [3, 4]]) The type of the data can be accessed through the :attr:`baseclass` attribute. )rrlrrs r _get_datazMaskedArray._get_datals|D$/222r)fgetc t|S)zF Return a flat iterator, or set a flattened version of self to value. )rrs rrzMaskedArray.flatsd###rc<|}||dd<dSr)r)r}r-ys rrzMaskedArray.flats JJLL!!!rc|jtd|j|_t|jtr |jdS|jS)a The filling value of the masked array is a scalar. When setting, None will set to a default based on the data type. Examples -------- >>> for dt in [np.int32, np.int64, np.float64, np.complex128]: ... np.ma.array([0, 1], dtype=dt).get_fill_value() ... 999999 999999 1e+20 (1e+20+0j) >>> x = np.ma.array([0, 1.], fill_value=-np.inf) >>> x.fill_value -inf >>> x.fill_value = np.pi >>> x.fill_value 3.1415926535897931 # may vary Reset to default: >>> x.fill_value = None >>> x.fill_value 1e+20 Nr)rrPrr!rrs rrMzMaskedArray.fill_valuesO<   #0tzBBD  d& 0 0 (#B' 'rct||j}|jdkstjdt d|j}| ||_dS||d<dS)NrzNon-scalar arrays for the fill value are deprecated. Use arrays with scalar values instead. The filled function still supports any array as `fill_value`.rrr)rPrrrrDeprecationWarningr)r}r-rrs rrMzMaskedArray.fill_valuesr"5$*55{a M<#q  2 2 2 2 &  %D   %KOOOrc|j}|tur|jS||j}nt ||j}|t urtj|S|jj 1|j d}t||j|n| s|jS|j d} tj |||n#ttf$rJt!|t"}|t"}tj|||f}YnAt($r5|jjr|rtj||j}n|j}YnwxYw|S)a Return a copy of self, with masked values filled with a given value. **However**, if there are no masked values to fill, self will be returned instead as an ndarray. Parameters ---------- fill_value : array_like, optional The value to use for invalid entries. Can be scalar or non-scalar. If non-scalar, the resulting ndarray must be broadcastable over input array. Default is None, in which case, the `fill_value` attribute of the array is used instead. Returns ------- filled_array : ndarray A copy of ``self`` with invalid entries replaced by *fill_value* (be it the function argument or the attribute of ``self``), or ``self`` itself as an ndarray if there are no invalid entries to be replaced. Notes ----- The result is **not** a MaskedArray! Examples -------- >>> x = np.ma.array([1,2,3,4,5], mask=[0,0,1,0,1], fill_value=-999) >>> x.filled() array([ 1, 2, -999, 4, -999]) >>> x.filled(fill_value=1000) array([ 1, 2, 1000, 4, 1000]) >>> type(x.filled()) Subclassing is preserved. This means that if, e.g., the data part of the masked array is a recarray, `filled` returns a recarray: >>> x = np.array([(-1, 2), (-3, 4)], dtype='i8,i8').view(np.recarray) >>> m = np.ma.array(x, mask=[(True, False), (False, True)]) >>> m.filled() rec.array([(999999, 2), ( -3, 999999)], dtype=[('f0', '|t jtj|j}|S)a Return all the non-masked data as a 1-D array. Returns ------- data : ndarray A new `ndarray` holding the non-masked data is returned. Notes ----- The result is **not** a MaskedArray! Examples -------- >>> x = np.ma.array(np.arange(5), mask=[0]*2 + [1]*3) >>> x.compressed() array([0, 1]) >>> type(x.compressed()) )rrrjrqrr8rrp)r}rms rr9zMaskedArray.compressedsN,}TZ(( :V # #== dj0I0I!J!JKKD rc.|j|j}}tj|}||||t |}|||tur||||_|S)a+ Return `a` where condition is ``True``. If condition is a `~ma.MaskedArray`, missing values are considered as ``False``. Parameters ---------- condition : var Boolean 1-d array selecting which entries to return. If len(condition) is less than the size of a along the axis, then output is truncated to length of condition array. axis : {None, int}, optional Axis along which the operation must be performed. out : {None, ndarray}, optional Alternative output array in which to place the result. It must have the same shape as the expected output but the type will be cast if necessary. Returns ------- result : MaskedArray A :class:`~ma.MaskedArray` object. Notes ----- Please note the difference with :meth:`compressed` ! The output of :meth:`compress` has a mask, the output of :meth:`compressed` does not. Examples -------- >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4) >>> x masked_array( data=[[1, --, 3], [--, 5, --], [7, --, 9]], mask=[[False, True, False], [ True, False, True], [False, True, False]], fill_value=999999) >>> x.compress([1, 0, 1]) masked_array(data=[1, 3], mask=[False, False], fill_value=999999) >>> x.compress([1, 0, 1], axis=1) masked_array( data=[[1, 3], [--, --], [7, 9]], mask=[[False, False], [ True, True], [False, False]], fill_value=999999) rrtr) rjrqrr0r8rlr^rr)r}r'rrtrjrq_news rr8zMaskedArray.compress5sx*djJy)) ~~id~<<AA$t**MM $    ==DJ rctr#|j}|tur |j}n$|j}|jdkr|jn|j}t|jD]}|j ||kr|dz}tj ||| f|}tj |d|df|}tj ||| f|}tj |d|df|}t|jd}||}t!||tn||j}|S)zq Replace masked values with masked_print_option, casting all innermost dtypes to object. rrrrr)rrWrqrrjr _print_width_print_width_1drangerrrr:rrrr]rNrM) r}rorIrm print_widthrindrrdtypes r_insert_masked_printz MaskedArray._insert_masked_print}s\  & & ( ( /:Dv~~jz59IMMt00$($8!$),,KKDz$'+55)Q. htcC4[tDDD!~s1vs1v.>TJJJ htcC4[tDDD!~s1vs1v.>TJJJ.tz3??kk&))&sD2EFFFF++do..C rcDt|Sr)r+rrs rrzMaskedArray.__str__s4,,..///rc  |jtjurd}n |jj}tjjdkr|jdk}t|dt|zt|t|j t|j t|j }t|j j}d|rdnd|rd nd }t"||zSd |d }tjj|j  p#tj|jp |jd k}gd}|r|dt/jd|jddD} d| r`i | |d <|ddD]E} t/jt||d zt| z } d| z | <Fd}nfd|D |dz}itj|d ddzdd<tj|j d ddzdd<t9|j d<|r,tjj|j d<d fd |D} || zd!zS)"z1 Literal string representation. r qr )rnlenrmrorrz{}_{}rshortflxrmasked_(r)rmrorMrc3"K|] }|dkV dS)rNr)rdims rrz'MaskedArray.__repr__..s&!F!Fs#(!F!F!F!F!F!FrNrrrci|]}|dz S)rr)rr min_indents r z(MaskedArray.__repr__..s 999qq# *999r z, rmzdata=,) separatorprefixsuffixrozmask=rMz, c3^K|]'}d|||V(dS)z{}{}={}N)format)rrindentsreprss rrz'MaskedArray.__repr__..sQ     WQZE!H 5 5      rr%)rrrrcore arrayprint_get_legacy_print_moderr[r<r+rqrMrrrr(_legacy_print_templatesdtype_is_impliedrrorr"rvrr array2stringrreprdtype_short_reprr)r}ris_long parameters is_structuredkeyr% dtype_neededkeys is_one_rowrrrUr)r r*s @@@rr[zMaskedArray.__repr__s; ?bj ( (DD?+D 7  4 4 6 6# = =i!mG3t99_YY__))$*oo J!!122M..!.w&1EC+3/*< <"4""""33DJ?? ?  F49    IN .--  ! KK \!F!Fdj"o!F!F!FFF   #G%GDG !""X % %LS$q'1A-B-BSVV-KLL 1W FF:999D999Gd]F  % % ' '6?W, f  J6?W, f #4?33l  MW/@@LLE'N          $$rct|t|rdSt|dd}|durt|dd}|j|kS|duS)NF__array_ufunc____array_priority__i)r!r^rr<)r}other array_ufuncother_prioritys r_delegate_binopzMaskedArray._delegate_binopsk eT$ZZ ( ( 5e%6>> %  $U,@(KKN*^; ;$& &rc^t|}|j}t||d}t|}|jj|t jt jfvrtStj ||j }tj ||d}||_||} |tjd|jk}n|j} || |} t%| tjt(fr |rt*n| S|t,urv|t jt jfvr\tj||||| } |j | j kr,tj || j }| t5|} | ||| _| jY t;| jtj} n1#t<t>f$rt;dtj} YnwxYw| | _| S)aCompare self with other using operator.eq or operator.ne. When either of the elements is masked, the result is masked as well, but the underlying boolean data are still set, with self and other considered equal if both are masked, and unequal otherwise. For structured arrays, all fields are combined, with masked values ignored. The result is masked if all fields were masked, with self and other considered equal only if both were fully masked. TrNrir) rYrorvrXrroperatoreqneNotImplementedrr r broadcast_torqrNrrmr!r rrwrrr=rlr^rrrPrrI) r}r=compareomasksmaskroodatabroadcast_shape sbroadcastsdatacheckrs r _comparisonzMaskedArray._comparisons  ue$/// :  'x{HK888%% !l477=OdKKKJ#J %%e,,EBGB 333DDIEu%% ebh- . . -!,66u , v  'hk8;-G"G"G HT775%#8#8%@@EzU[((tU[99>>@@ 4::&& 4       ( 9():BHEEz* 9 9 9(rx88 9 $E  sG55+H#"H#cB||tjS)aCheck whether other equals self elementwise. When either of the elements is masked, the result is masked as well, but the underlying boolean data are still set, with self and other considered equal if both are masked, and unequal otherwise. For structured arrays, all fields are combined, with masked values ignored. The result is masked if all fields were masked, with self and other considered equal only if both were fully masked. )rPrCrDr}r=s r__eq__zMaskedArray.__eq__Fx{333rcB||tjS)aCheck whether other does not equal self elementwise. When either of the elements is masked, the result is masked as well, but the underlying boolean data are still set, with self and other considered equal if both are masked, and unequal otherwise. For structured arrays, all fields are combined, with masked values ignored. The result is masked if all fields were masked, with self and other considered equal only if both were fully masked. )rPrCrErRs r__ne__zMaskedArray.__ne__SrTrcB||tjSr)rPrClerRs r__le__zMaskedArray.__le__ax{333rcB||tjSr)rPrCltrRs r__lt__zMaskedArray.__lt__drZrcB||tjSr)rPrCgerRs r__ge__zMaskedArray.__ge__grZrcB||tjSr)rPrCgtrRs r__gt__zMaskedArray.__gt__jrZrcZ||rtSt||S)zD Add self to other, and return a new masked array. )r@rFrrRs r__add__zMaskedArray.__add__ms0    & & "! !4rc"t||S)zD Add other to self, and return a new masked array. )rrRs r__radd__zMaskedArray.__radd__vs5$rcZ||rtSt||S)zK Subtract other from self, and return a new masked array. )r@rFrrRs r__sub__zMaskedArray.__sub__s0    & & "! !e$$$rc"t||S)zK Subtract self from other, and return a new masked array. )rrRs r__rsub__zMaskedArray.__rsub__s t$$$rcZ||rtSt||S)z6Multiply self by other, and return a new masked array.)r@rFrrRs r__mul__zMaskedArray.__mul__s.    & & "! !e$$$rc"t||S)zI Multiply other by self, and return a new masked array. )rrRs r__rmul__zMaskedArray.__rmul__st$$$rcZ||rtSt||SzI Divide other into self, and return a new masked array. )r@rFrHrRs r__div__zMaskedArray.__div__s0    & & "! !dE"""rcZ||rtSt||Srq)r@rFrrRs r __truediv__zMaskedArray.__truediv__s0    & & "! !4'''rc"t||SzI Divide self into other, and return a new masked array. )rrRs r __rtruediv__zMaskedArray.__rtruediv__s 5$'''rcZ||rtSt||Srq)r@rFrSrRs r __floordiv__zMaskedArray.__floordiv__s0    & & "! !D%(((rc"t||Srv)rSrRs r __rfloordiv__zMaskedArray.__rfloordiv__s E4(((rcZ||rtSt||S)zQ Raise self to the power other, masking the potential NaNs/Infs )r@rFrrRs r__pow__zMaskedArray.__pow__s0    & & "! !T5!!!rc"t||S)zQ Raise other to the power self, masking the potential NaNs/Infs )rrRs r__rpow__zMaskedArray.__rpow__s UD!!!rct|}|jturM|turC|r/t |j|j|_|xj|z c_n|tur|xj|z c_t|}tj |j|j d|}|j ||S)z. Add other to self in-place. r) rYrqrr!rurrrXrrr^rj__iadd__r}r=r other_datas rrzMaskedArray.__iadd__s ENN :  15577+DJ CC  a  a U^^ Xdj**:*?*?*B*BJOO  J''' rct|}|jturM|turC|r/t |j|j|_|xj|z c_n|tur|xj|z c_t|}tj |j|j d|}|j ||S)z5 Subtract other from self in-place. r) rYrqrr!rurrrXrrr^rj__isub__rs rrzMaskedArray.__isub__ ENN :  15577+DJ CC  a f__ JJ!OJJU^^ Xdj**:*?*?*B*BJOO  J''' rct|}|jturM|turC|r/t |j|j|_|xj|z c_n|tur|xj|z c_t|}tj |j|j d|}|j ||S)z3 Multiply self by other in-place. r) rYrqrr!rurrrXrrr^rj__imul__rs rrzMaskedArray.__imul__rrc"t|}t|j|}t |}t ||}|rHttj \}}tj ||j ||}|xj |zc_ tj |j |j d|}|j||S)z1 Divide self by other in-place. r)rXrrrjrYrvr!rrrHrrr^rq__idiv__r}r=rdom_mask other_masknew_maskrrCs rrzMaskedArray.__idiv__ s U^^ $&&// JGGU^^ :x00 <<>> G#BI.IQj.33D99:GGJ h Xdj**:*?*?*B*BJOO  J''' rc"t|}t|j|}t |}t ||}|rHttj \}}tj ||j ||}|xj |zc_ tj |j |j d|}|j||S)z7 Floor divide self by other in-place. r)rXrrrjrYrvr!rrrSrrr^rq __ifloordiv__rs rrzMaskedArray.__ifloordiv__s U^^ $&&// JGGU^^ :x00 <<>> G#BO4IQj.33D99:GGJ h Xdj**:*?*?*B*BJOO    ,,, rc"t|}t|j|}t |}t ||}|rHttj \}}tj ||j ||}|xj |zc_ tj |j |j d|}|j||S)z6 True divide self by other in-place. r)rXrrrjrYrvr!rrrrrr^rq __itruediv__rs rrzMaskedArray.__itruediv__1s U^^ $&&// JGGU^^ :x00 <<>> G#BN3IQj.33D99:GGJ h Xdj**:*?*?*B*BJOO   +++ rct|}tj|j|jd|}t |}tjdd5|j |dddn #1swxYwYtj tj |j}| rG|jtur|xj|zc_n||_tj|j|j|t!||}t!|j||_|S)z; Raise self to the power other, in place. rrrNr)rXrrrqrr^rYrrj__ipow__rprpr!rrrMrv)r}r=rrrrrs rrzMaskedArray.__ipow__DsT U^^ Xdj**:*?*?*B*BJOO U^^ [( ; ; ; , , J   + + + , , , , , , , , , , , , , , ,.TZ!8!899 ;;== Bz'' g% $ Idj$/ A A A A:w//TZ22  s(BBBc|jdkrtd|jr"tjddt jSt|S)z$ Convert to float. r7Only length-1 arrays can be converted to Python scalarsz,Warning: converting a masked element to nan.rr) rrrqrrrnanrr?rs r __float__zMaskedArray.__float__Ysd 9q==011 1 Z  MHUV W W W W6MTYY[[!!!rc|jdkrtd|jrtdt |S)z" Convert to int. rrz.Cannot convert masked element to a Python int.)rrrqrrr?rs r__int__zMaskedArray.__int__fsV 9q==011 1 Z NLMM M499;;rc|jjt|}||j|S)a The imaginary part of the masked array. This property is a view on the imaginary part of this `MaskedArray`. See Also -------- real Examples -------- >>> x = np.ma.array([1+1.j, -2j, 3.45+1.6j], mask=[False, True, False]) >>> x.imag masked_array(data=[1.0, --, 1.6], mask=[False, True, False], fill_value=1e+20) )rjimagrlr^rwrqr}rUs rrzMaskedArray.imagr<(%%d4jj114:&&& rc|jjt|}||j|S)a The real part of the masked array. This property is a view on the real part of this `MaskedArray`. See Also -------- imag Examples -------- >>> x = np.ma.array([1+1.j, -2j, 3.45+1.6j], mask=[False, True, False]) >>> x.real masked_array(data=[1.0, --, 3.45], mask=[False, True, False], fill_value=1e+20) )rjrealrlr^rwrqrs rrzMaskedArray.realrrc |tjurind|i}|j}t|jtjrU|t ur%tj|jtj }| t|j}|t ur|jdkr!|dvrtj ||j dS|H|ddr+tj|jtj|j S|jSt%||j  d} D]}||j|z}|ddrt'|j} D]}d||<n fd t)|jD}tj||tjS|t,urd S|jd|tjd |S) a Count the non-masked elements of the array along the given axis. Parameters ---------- axis : None or int or tuple of ints, optional Axis or axes along which the count is performed. The default, None, performs the count over all the dimensions of the input array. `axis` may be negative, in which case it counts from the last to the first axis. .. versionadded:: 1.10.0 If this is a tuple of ints, the count is performed on multiple axes, instead of a single axis or all the axes as before. 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 array. Returns ------- result : ndarray or scalar An array with the same shape as the input array, with the specified axis removed. If the array is a 0-d array, or if `axis` is None, a scalar is returned. See Also -------- ma.count_masked : Count masked elements in array or along a given axis. Examples -------- >>> import numpy.ma as ma >>> a = ma.arange(6).reshape((2, 3)) >>> a[1, :] = ma.masked >>> a masked_array( data=[[0, 1, 2], [--, --, --]], mask=[[False, False, False], [ True, True, True]], fill_value=999999) >>> a.count() 3 When the `axis` keyword is specified an array of appropriate size is returned. >>> a.count(axis=0) array([1, 1, 1]) >>> a.count(axis=1) array([3, 0]) r!rrNr)rrrNF)rrc"g|] \}}|v | Srr)rrraxess rrz%MaskedArray.count..s-...$!Q }},}}rrrr)rr rqr!rmmatrixrrrr rlr^ AxisErrorrr*r rintprru enumeraterrwr) r}rr!rritemsaxout_dimsrSrs @rrAzMaskedArray.countsp 2;..Z4J J di + + (F{{HTZrx888tDI''A ;;zRy((,DtyAAAAq::j%00O8DIRWDINNNNy 'di88DE ( (B'zz*e,, . ++$$A"#HQKK$....)DJ*?*?...78U"'::: : 6>>1x;T;;F;;;rrc~|dvr|jjjrdnd}tj|j|t |}|||jtur9tj|j| |j |_n t|_|S)af Returns a 1D version of self, as a view. Parameters ---------- order : {'C', 'F', 'A', 'K'}, optional The elements of `a` are read using this index order. 'C' means to index the elements in C-like order, with the last axis index changing fastest, back to the first axis index changing slowest. 'F' means to index the elements in Fortran-like index order, with the first index changing fastest, and the last index changing slowest. Note that the 'C' and 'F' options take no account of the memory layout of the underlying array, and only refer to the order of axis indexing. 'A' means to read the elements in Fortran-like index order if `m` is Fortran *contiguous* in memory, C-like order otherwise. 'K' means to read the elements in the order they occur in memory, except for reversing the data when strides are negative. By default, 'C' index order is used. (Masked arrays currently use 'A' on the data when 'K' is passed.) Returns ------- MaskedArray Output view is of shape ``(self.size,)`` (or ``(np.ma.product(self.shape),)``). Examples -------- >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4) >>> x masked_array( data=[[1, --, 3], [--, 5, --], [7, --, 9]], mask=[[False, True, False], [ True, False, True], [False, True, False]], fill_value=999999) >>> x.ravel() masked_array(data=[1, --, 3, --, 5, --, 7, --, 9], mask=[False, True, False, True, False, True, False, True, False], fill_value=999999) kKaArrr) rjrfncrrrlr^rrqrrr)r}rrs rrzMaskedArray.ravel sf F??:+/8CCSE M$*E 2 2 2 7 7T C C t :V # #mDJe<<<DDQWMMAGGAGrc,||dd|jj|i|t |}|||j}|tur|j|i||_|S)a Give a new shape to the array without changing its data. Returns a masked array containing the same data, but with a new shape. The result is a view on the original array; if this is not possible, a ValueError is raised. Parameters ---------- shape : int or tuple of ints The new shape should be compatible with the original shape. If an integer is supplied, then the result will be a 1-D array of that length. order : {'C', 'F'}, optional Determines whether the array data should be viewed as in C (row-major) or FORTRAN (column-major) order. Returns ------- reshaped_array : array A new view on the array. See Also -------- reshape : Equivalent function in the masked array module. numpy.ndarray.reshape : Equivalent method on ndarray object. numpy.reshape : Equivalent function in the NumPy module. Notes ----- The reshaping operation cannot guarantee that a copy will not be made, to modify the shape in place, use ``a.shape = s`` Examples -------- >>> x = np.ma.array([[1,2],[3,4]], mask=[1,0,0,1]) >>> x masked_array( data=[[--, 2], [3, --]], mask=[[ True, False], [False, True]], fill_value=999999) >>> x = x.reshape((4,1)) >>> x masked_array( data=[[--], [2], [3], [--]], mask=[[ True], [False], [False], [ True]], fill_value=999999) rrr) rr*rjrrlr^rrqr)r}rrrUros rrzMaskedArray.reshapeIst  FJJw44 555##Q1&1166tDzzBBD!!!z v  '4<5f55FL rc$d}t|)av .. warning:: This method does nothing, except raise a ValueError exception. A masked array does not own its data and therefore cannot safely be resized in place. Use the `numpy.ma.resize` function instead. This method is difficult to implement safely and may be deprecated in future releases of NumPy. zoA masked array does not own its data and therefore cannot be resized. Use the numpy.ma.resize function instead.)rI)r}rrefcheckrerrmsgs rrzMaskedArray.resizes=   rraisecV|jrj|jtur\|j|}t|d}t|dd}||j||}||}|j||||jturt|turdSt|}t|tur||d|n|||j|t|dd}||_dS)aD Set storage-indexed locations to corresponding values. Sets self._data.flat[n] = values[n] for each n in indices. If `values` is shorter than `indices` then it will repeat. If `values` has some masked values, the initial mask is updated in consequence, else the corresponding values are unmasked. Parameters ---------- indices : 1-D array_like Target indices, interpreted as integers. values : array_like Values to place in self._data copy at target indices. mode : {'raise', 'wrap', 'clip'}, optional Specifies how out-of-bounds indices will behave. 'raise' : raise an error. 'wrap' : wrap around. 'clip' : clip to the range. Notes ----- `values` can be a scalar or length 1 array. Examples -------- >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4) >>> x masked_array( data=[[1, --, 3], [--, 5, --], [7, --, 9]], mask=[[False, True, False], [ True, False, True], [False, True, False]], fill_value=999999) >>> x.put([0,4,8],[10,20,30]) >>> x masked_array( data=[[10, --, 3], [--, 20, --], [7, --, 30]], mask=[[False, True, False], [ True, False, True], [False, True, False]], fill_value=999999) >>> x.put(4,999) >>> x masked_array( data=[[10, --, 3], [--, 999, --], [7, --, 30]], mask=[[False, True, False], [ True, False, True], [False, True, False]], fill_value=999999) FrTrhmodeNr ) rrqrrrrrjrrYrZrs)r}ravaluesrrors rrzMaskedArray.puts(z > #dj66:g&DW5111GFd;;;F MM'- ( ( (tenGTE]F wT222 :  GFOOv$=$= F    6??f $ $ EE'5tE , , , , EE'6>> x = np.ma.array([1, 2, 3], mask=[0, 1, 1]) >>> x.ids() (166670640, 166659832) # may vary If the array has no mask, the address of `nomask` is returned. This address is typically not close to the data in memory: >>> x = np.ma.array([1, 2, 3]) >>> x.ids() (166691080, 3083169284) # may vary )rqrctypesrmidrs rr`zMaskedArray.idss?, :  K$bjj1 1  $*"3"899rc|jdS)a Return a boolean indicating whether the data is contiguous. Parameters ---------- None Examples -------- >>> x = np.ma.array([1, 2, 3]) >>> x.iscontiguous() True `iscontiguous` returns one of the flags of the masked array: >>> x.flags C_CONTIGUOUS : True F_CONTIGUOUS : True OWNDATA : False WRITEABLE : True ALIGNED : True WRITEBACKIFCOPY : False CONTIGUOUS)rrs r iscontiguouszMaskedArray.iscontiguous s2z,''rc|tjurind|i}t|j|fi|}|j|djdd|i|t|}|jr| |n |rtS|S|djd||d|t|tr|js|r| ||S)a Returns True if all elements evaluate to True. The output array is masked where all the values along the given axis are masked: if the output would have been a scalar and that all the values are masked, then the output is `masked`. Refer to `numpy.all` for full documentation. See Also -------- numpy.ndarray.all : corresponding function for ndarrays numpy.all : equivalent function Examples -------- >>> np.ma.array([1,2,3]).all() True >>> a = np.ma.array([1,2,3], mask=True) >>> (a.all() is np.ma.masked) True r!NTrr r) rr r"rqrNrrlr^rrwrwr!rr}rrtr!rrors rrzMaskedArray.all's0 2;..Z4J D;;F;; ;% D!!%::4:6::??T KKAv  d####  H D;4S;;F;;; c; ' ' &x &4 &%%% rc|tjurind|i}t|j|fi|}|j|djdd|i|t|}|jr| |n |rt}|S|djd||d|t|tr|js|r| ||S)aS Returns True if any of the elements of `a` evaluate to True. Masked values are considered as False during computation. Refer to `numpy.any` for full documentation. See Also -------- numpy.ndarray.any : corresponding function for ndarrays numpy.any : equivalent function r!NFrr r) rr r"rqrNr!rlr^rrwrwr!rrs rr!zMaskedArray.anyOs 2;..Z4J D;;F;; ;& E""&;;D;F;;@@dLLAv  d#### H E>> import numpy.ma as ma >>> x = ma.array(np.eye(3)) >>> x masked_array( data=[[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]], mask=False, fill_value=1e+20) >>> x.nonzero() (array([0, 1, 2]), array([0, 1, 2])) Masked elements are ignored. >>> x[1, 1] = ma.masked >>> x masked_array( data=[[1.0, 0.0, 0.0], [0.0, --, 0.0], [0.0, 0.0, 1.0]], mask=[[False, False, False], [False, True, False], [False, False, False]], fill_value=1e+20) >>> x.nonzero() (array([0, 2]), array([0, 2])) Indices can also be grouped by element. >>> np.transpose(x.nonzero()) array([[0, 0], [2, 2]]) A common use for ``nonzero`` is to find the indices of an array, where a condition is True. Given an array `a`, the condition `a` > 3 is a boolean array and since False is interpreted as 0, ma.nonzero(a > 3) yields the indices of the `a` where the condition is true. >>> a = ma.array([[1,2,3],[4,5,6],[7,8,9]]) >>> a > 3 masked_array( data=[[False, False, False], [ True, True, True], [ True, True, True]], mask=False, fill_value=True) >>> ma.nonzero(a > 3) (array([1, 1, 1, 2, 2, 2]), array([0, 1, 2, 0, 1, 2])) The ``nonzero`` method of the condition array can also be called. >>> (a > 3).nonzero() (array([1, 1, 1, 2, 2, 2]), array([0, 1, 2, 0, 1, 2])) rFr)rrNrrs rrzMaskedArray.nonzeroms.@dkk!nn511199;;;rrcB|j}|tur:t||||}||S||||}||dd|S)z8 (this docstring should be overwritten) )offsetaxis1axis2rt)rrrrrr )rqrrrrrFrNr) r}rrrrrtrrUrrs rrzMaskedArray.traces J ;;WW]]&U'*#,,F=='' ' V5 FFA88E??))!,,00bc0BB Brc(t||||S)a a.dot(b, out=None) Masked dot product of two arrays. Note that `out` and `strict` are located in different positions than in `ma.dot`. In order to maintain compatibility with the functional version, it is recommended that the optional arguments be treated as keyword only. At some point that may be mandatory. .. versionadded:: 1.10.0 Parameters ---------- b : masked_array_like Inputs array. out : masked_array, optional Output argument. This must have the exact kind that would be returned if it was not used. In particular, it must have the right type, must be C-contiguous, and its dtype must be the dtype that would be returned for `ma.dot(a,b)`. This is a performance feature. Therefore, if these conditions are not met, an exception is raised, instead of attempting to be flexible. 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. .. versionadded:: 1.10.2 See Also -------- numpy.ma.dot : equivalent function )rtstrict)dot)r}rrtrs rrzMaskedArray.dotsJ4F3333rc4|tjurind|i}|j}t||fi|}|y|dj|fd|i|}t |dd} | r8|t|}| |n |rt}|S|dj|f||d|}t|tr:t|} | turt|jx} |_|| _|S)aW Return the sum of the array elements over the given axis. Masked elements are set to 0 internally. Refer to `numpy.sum` for full documentation. See Also -------- numpy.ndarray.sum : corresponding function for ndarrays numpy.sum : equivalent function Examples -------- >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4) >>> x masked_array( data=[[1, --, 3], [--, 5, --], [7, --, 9]], mask=[[False, True, False], [ True, False, True], [False, True, False]], fill_value=999999) >>> x.sum() 25 >>> x.sum(axis=1) masked_array(data=[4, 5, 16], mask=[False, False, False], fill_value=999999) >>> x.sum(axis=0) masked_array(data=[8, 5, 12], mask=[False, False, False], fill_value=999999) >>> print(type(x.sum(axis=0, dtype=np.int64)[0])) r!Nrrrrrt)rr rqr"rNrrrlr^rwrwr!rrYrrurr r}rrrtr!rrqrrUrndimoutmasks rrzMaskedArray.sums9N 2;..Z4J "5$99&99 ;'T[[^^'DDEDVDDFFFA..E T$ZZ00""7++++ M#Q#DI3II&II c; ' ' #cllG&  &4SY&?&??#)"GL rc:|d|||}|1t|tr||j|S|t|}||j|S)a Return the cumulative sum of the array elements over the given axis. Masked values are set to 0 internally during the computation. However, their position is saved, and the result will be masked at the same locations. Refer to `numpy.cumsum` for full documentation. Notes ----- The mask is lost if `out` is not a valid :class:`ma.MaskedArray` ! Arithmetic is modular when using integer types, and no error is raised on overflow. See Also -------- numpy.ndarray.cumsum : corresponding function for ndarrays numpy.cumsum : equivalent function Examples -------- >>> marr = np.ma.array(np.arange(10), mask=[0,0,0,1,1,1,0,0,0,0]) >>> marr.cumsum() masked_array(data=[0, 1, 3, --, --, --, 9, 16, 24, 33], mask=[False, False, False, True, True, True, False, False, False, False], fill_value=999999) rrrrt) rNrCr!rrwrorlr^rqr}rrrtrUs rrCzMaskedArray.cumsumCs@Q&&D3&GG ?#{++ + ***JT$ZZ((4:&&& rc4|tjurind|i}|j}t||fi|}|y|dj|fd|i|}t |dd} | r8|t|}| |n |rt}|S|dj|f||d|}t|tr:t|} | turt|jx} |_|| _|S)a Return the product of the array elements over the given axis. Masked elements are set to 1 internally for computation. Refer to `numpy.prod` for full documentation. Notes ----- Arithmetic is modular when using integer types, and no error is raised on overflow. See Also -------- numpy.ndarray.prod : corresponding function for ndarrays numpy.prod : equivalent function r!Nrrrrr)rr rqr"rNrrrlr^rwrwr!rrYrrurrrs rrzMaskedArray.prodls8$ 2;..Z4J "5$99&99 ;(T[[^^(EEUEfEEFFFA..E T$ZZ00""7++++ M$Q$TJCJJ6JJ c; ' ' #cllG&  &4SY&?&??#)"GL rc:|d|||}|1t|tr||j|S|t|}||j|S)a Return the cumulative product of the array elements over the given axis. Masked values are set to 1 internally during the computation. However, their position is saved, and the result will be masked at the same locations. Refer to `numpy.cumprod` for full documentation. Notes ----- The mask is lost if `out` is not a valid MaskedArray ! Arithmetic is modular when using integer types, and no error is raised on overflow. See Also -------- numpy.ndarray.cumprod : corresponding function for ndarrays numpy.cumprod : equivalent function rr)rNrBr!rrwrqrlr^rs rrBzMaskedArray.cumprods,Q''TC'HH ?#{++ , +++JT$ZZ((4:&&& rc,|tjurind|i}|jtur#t jd||d|d}nd}|t |jjtj tj frtjd}n:t |jjtj rtjd}d}|jd||d|}|jdd |i|} | jdkr| d krt"}n+|r!|j|d z| z }n|d z| z }|e||_t'|t(rGt+|} | turt-|jx} |_t+|| _|S|S) a Returns the average of the array elements along given axis. Masked entries are ignored, and result elements which are not finite will be masked. Refer to `numpy.mean` for full documentation. See Also -------- numpy.ndarray.mean : corresponding function for ndarrays numpy.mean : Equivalent function numpy.ma.average : Weighted average. Examples -------- >>> a = np.ma.array([1,2,3], mask=[False, False, True]) >>> a masked_array(data=[1, 2, --], mask=[False, False, True], fill_value=999999) >>> a.mean() 1.5 r!rrFNf8f4Trrr)rr rqrrrrarr^ntypesintegerr mufloat16rrArrwrr!rrYru) r}rrrtr!rrUis_float16_resultdsumcntrrs rrzMaskedArray.means4 2;..Z4J :  !UWW\Ct5CCFCCBGFF % }djo /MNN-HTNNEE @@-HTNNE(,%48=U==f==D$*11$1&11CyBC1HH" )S99S ?CH#{++ /!#,,f$$*8*C*CCGci&v J rcb|||}|s||z S|t||z S)a Compute the anomalies (deviations from the arithmetic mean) along the given axis. Returns an array of anomalies, with the same shape as the input and where the arithmetic mean is computed along the given axis. Parameters ---------- axis : int, optional Axis over which the anomalies are taken. The default is to use the mean of the flattened array as reference. dtype : dtype, optional Type to use in computing the variance. For arrays of integer type the default is float32; for arrays of float types it is the same as the array type. See Also -------- mean : Compute the mean of the array. Examples -------- >>> a = np.ma.array([1,2,3]) >>> a.anom() masked_array(data=[-1., 0., 1.], mask=False, fill_value=1e+20) )rr)r}rrrs rrzMaskedArray.anoms=> IIdE " " /!8O+a... .rc"|tjurind|i}|jturYt jd||||d|d}|1t |tr|t|S|S|j dd|i||z }|| ||dz } t|rtj | dz} n| | z} t| j|fi||t#|} | jr@t'|jj|fi||d k| _| |n|t-| rmt.} |dt |trd |_|dn0|jjd vrd } t7| tj|_|S|8| |_t |tr|| j|S| S) au Returns the variance of the array elements along given axis. Masked entries are ignored, and result elements which are not finite will be masked. Refer to `numpy.var` for full documentation. See Also -------- numpy.ndarray.var : corresponding function for ndarrays numpy.var : Equivalent function r!)rrrtddofrNrTr!rrbiu>Masked data information would be lost in one or more location.)rr rqrrrr!rrwrArrrrrHrrlr^rrvrrrYrwrrr(rrro) r}rrrtrr!rrGrdanomdvarrrs rrzMaskedArray.vars? 2;..Z4J :  %''+(4u#D(( &(((*,Cc;//,OOF+++ Jdj--d-f--4tyyuty<<<    N5))Q.EE UNEiei////55::4::FF 9  !?!?!?!?#(LLDJ   d # # # # T]] Dc;//& CHOOD))))Y^u,,.F#F+++!vCH ?CH#{++ + ***J rc|tjurind|i}|j||||fi|}|tur+|tj|d|d|St |}|S)a> Returns the standard deviation of the array elements along given axis. Masked entries are ignored. Refer to `numpy.std` for full documentation. See Also -------- numpy.ndarray.std : corresponding function for ndarrays numpy.std : Equivalent function r!Ng?rrtr)rr rrwrr)r}rrrtrr!rrs rrzMaskedArray.stdQs{ 2;..Z4JtxeS$99&99 v  csH==== ::D rcZ|j||t|}|jdkr"|j|_||n|jrt}||St|tr| |j|S)a Return each element rounded to the given number of decimals. Refer to `numpy.around` for full documentation. See Also -------- numpy.ndarray.round : corresponding function for ndarrays numpy.around : equivalent function )decimalsrtr) rjrrlr^rrqrrwr!rrw)r}rrtrUs rrzMaskedArray.roundis!!8!==BB4::NN ;??:FL    % % % % Z F ;M c; ' ' ( OODJ ' ' ' rc>|tjurt|}|R|rAtj|jtjr tj}nt|}nt|}| |}| |||S)a! Return an ndarray of indices that sort the array along the specified axis. Masked values are filled beforehand to `fill_value`. Parameters ---------- axis : int, optional Axis along which to sort. If None, the default, the flattened array is used. .. versionchanged:: 1.13.0 Previously, the default was documented to be -1, but that was in error. At some future date, the default will change to -1, as originally intended. Until then, the axis should be given explicitly when ``arr.ndim > 1``, to avoid a FutureWarning. kind : {'quicksort', 'mergesort', 'heapsort', 'stable'}, optional The sorting algorithm used. order : list, optional When `a` is an array with fields defined, this argument specifies which fields to compare first, second, etc. Not all fields need be specified. endwith : {True, False}, optional Whether missing values (if any) should be treated as the largest values (True) or the smallest values (False) When the array contains unmasked values at the same extremes of the datatype, the ordering of these values and the masked values is undefined. fill_value : scalar or None, optional Value used internally for the masked values. If ``fill_value`` is not None, it supersedes ``endwith``. Returns ------- index_array : ndarray, int Array of indices that sort `a` along the specified axis. In other words, ``a[index_array]`` yields a sorted `a`. See Also -------- ma.MaskedArray.sort : Describes sorting algorithms used. lexsort : Indirect stable sort with multiple keys. numpy.ndarray.sort : Inplace sort. Notes ----- See `sort` for notes on the different sorting algorithms. Examples -------- >>> a = np.ma.array([3,2,1], mask=[False, False, True]) >>> a masked_array(data=[3, 2, --], mask=[False, False, True], fill_value=999999) >>> a.argsort() array([1, 0, 2]) Nrr(r) rr rrBrrCrrrrNr-)r}rr(rendwithrMrNs rr-zMaskedArray.argsorts@ 2;  *400D   6=R[99:!#JJ!3D!9!9JJ/55 Z((~~4d%~@@@rrc|t|}||t}|tjurdnt |}||||S)a< Return array of indices to the minimum values along the given axis. Parameters ---------- axis : {None, integer} If None, the index is into the flattened array, otherwise along the specified axis fill_value : scalar or None, optional Value used to fill in the masked values. If None, the output of minimum_fill_value(self._data) is used instead. out : {None, array}, optional Array into which the result can be placed. Its type is preserved and it must be of the right shape to hold the output. Returns ------- ndarray or scalar If multi-dimension input, returns a new ndarray of indices to the minimum values along the given axis. Otherwise, returns a scalar of index to the minimum values along the given axis. Examples -------- >>> x = np.ma.array(np.arange(4), mask=[1,1,0,0]) >>> x.shape = (2,2) >>> x masked_array( data=[[--, --], [2, 3]], mask=[[ True, True], [False, False]], fill_value=999999) >>> x.argmin(axis=0, fill_value=-1) array([0, 0]) >>> x.argmin(axis=0, fill_value=9) array([1, 1]) NFrtr!)rrNrlrrr rr,r}rrMrtr!rs rr,zMaskedArray.argminsjR  +D11J KK # # ( ( 1 1$ 3355hxx#x999rc|t|j}||t}|t jurdnt|}||||S)a Returns array of indices of the maximum values along the given axis. Masked values are treated as if they had the value fill_value. Parameters ---------- axis : {None, integer} If None, the index is into the flattened array, otherwise along the specified axis fill_value : scalar or None, optional Value used to fill in the masked values. If None, the output of maximum_fill_value(self._data) is used instead. out : {None, array}, optional Array into which the result can be placed. Its type is preserved and it must be of the right shape to hold the output. Returns ------- index_array : {integer_array} Examples -------- >>> a = np.arange(6).reshape(2,3) >>> a.argmax() 5 >>> a.argmax(0) array([1, 1, 1]) >>> a.argmax(1) array([2, 2]) NFr) rrjrNrlrrr rr+rs rr+zMaskedArray.argmaxslB  +DJ77J KK # # ( ( 1 1$ 3355hxx#x999rrc|jturtj||||dS|turdS||||||}t j||||d<dS)a Sort the array, in-place Parameters ---------- a : array_like Array to be sorted. axis : int, optional Axis along which to sort. If None, the array is flattened before sorting. The default is -1, which sorts along the last axis. kind : {'quicksort', 'mergesort', 'heapsort', 'stable'}, optional The sorting algorithm used. order : list, optional When `a` is a structured array, this argument specifies which fields to compare first, second, and so on. This list does not need to include all of the fields. endwith : {True, False}, optional Whether missing values (if any) should be treated as the largest values (True) or the smallest values (False) When the array contains unmasked values sorting at the same extremes of the datatype, the ordering of these values and the masked values is undefined. fill_value : scalar or None, optional Value used internally for the masked values. If ``fill_value`` is not None, it supersedes ``endwith``. Returns ------- sorted_array : ndarray Array of the same type and shape as `a`. See Also -------- numpy.ndarray.sort : Method to sort an array in-place. argsort : Indirect sort. lexsort : Indirect stable sort on multiple keys. searchsorted : Find elements in a sorted array. Notes ----- See ``sort`` for notes on the different sorting algorithms. Examples -------- >>> a = np.ma.array([1, 2, 5, 4, 3],mask=[0, 1, 0, 1, 0]) >>> # Default >>> a.sort() >>> a masked_array(data=[1, 3, 5, --, --], mask=[False, False, False, True, True], fill_value=999999) >>> a = np.ma.array([1, 2, 5, 4, 3],mask=[0, 1, 0, 1, 0]) >>> # Put missing values in the front >>> a.sort(endwith=False) >>> a masked_array(data=[--, --, 1, 3, 5], mask=[ True, True, False, False, False], fill_value=999999) >>> a = np.ma.array([1, 2, 5, 4, 3],mask=[0, 1, 0, 1, 0]) >>> # fill_value takes over endwith >>> a.sort(endwith=False, fill_value=3) >>> a masked_array(data=[1, --, --, 3, 5], mask=[False, True, True, False, False], fill_value=999999) rN)rr(rrMrr.)rqrrrrwr-rtake_along_axis)r}rr(rrrMsidxs rrzMaskedArray.sort(sN :   LDt5 A A A A F 6>> F||D'17DD&tT===S rc|tjurind|i}|j}t||fi|}|t |}|||jd||d|t|}|j r9| ||j rtj ||j |n |rt}|S||jd||d|}t|tr;t!|} | t"urt%|jx} |_|| _n@|jjdvrd} t/| tj |tj||S)as Return the minimum along a given axis. Parameters ---------- axis : None or int or tuple of ints, optional Axis along which to operate. By default, ``axis`` is None and the flattened input is used. .. versionadded:: 1.7.0 If this is a tuple of ints, the minimum is selected over multiple axes, instead of a single axis or all the axes as before. out : array_like, optional Alternative output array in which to place the result. Must be of the same shape and buffer length as the expected output. fill_value : scalar or None, optional Value used to fill in the masked values. If None, use the output of `minimum_fill_value`. 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 array. Returns ------- amin : array_like New array holding the result. If ``out`` was specified, ``out`` is returned. See Also -------- ma.minimum_fill_value Returns the minimum filling value for a given datatype. Examples -------- >>> import numpy.ma as ma >>> x = [[1., -2., 3.], [0.2, -0.7, 0.1]] >>> mask = [[1, 1, 0], [0, 0, 1]] >>> masked_x = ma.masked_array(x, mask) >>> masked_x masked_array( data=[[--, --, 3.0], [0.2, -0.7, --]], mask=[[ True, True, False], [False, False, True]], fill_value=1e+20) >>> ma.min(masked_x) -0.7 >>> ma.min(masked_x, axis=-1) masked_array(data=[3.0, -0.7], mask=[False, False], fill_value=1e+20) >>> ma.min(masked_x, axis=0, keepdims=True) masked_array(data=[[0.2, -0.7, 3.0]], mask=[[False, False, False]], fill_value=1e+20) >>> mask = [[1, 1, 1,], [1, 1, 1]] >>> masked_x = ma.masked_array(x, mask) >>> ma.min(masked_x, axis=0) masked_array(data=[--, --, --], mask=[ True, True, True], fill_value=1e+20, dtype=float64) r!Nr rrrr)rr rqr"rrNrrlr^rrwrrMrwr!rrYrrurrrr(rr r}rrtrMr!rrqrrUrrs rrzMaskedArray.min{sB 2;..Z4J "5$99&99  +D11J ;0T[[,,0.s..&,...2d4::.>.> { ""7+++<HIff&7wGGGG M,Z((,J$CJJ6JJ c; ' ' 2cllG&  &4SY&?&??#)"GLLy~&&&''' Ic26 1 1 1 1 rc|tjurind|i}|j}t||fi|}|t |}|||jd||d|t|}|j r9| ||j rtj ||j |n |rt}|S||jd||d|}t|tr;t!|} | t"urt%|jx} |_|| _n@|jjdvrd} t/| tj |tj||S)a Return the maximum along a given axis. Parameters ---------- axis : None or int or tuple of ints, optional Axis along which to operate. By default, ``axis`` is None and the flattened input is used. .. versionadded:: 1.7.0 If this is a tuple of ints, the maximum is selected over multiple axes, instead of a single axis or all the axes as before. out : array_like, optional Alternative output array in which to place the result. Must be of the same shape and buffer length as the expected output. fill_value : scalar or None, optional Value used to fill in the masked values. If None, use the output of maximum_fill_value(). 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 array. Returns ------- amax : array_like New array holding the result. If ``out`` was specified, ``out`` is returned. See Also -------- ma.maximum_fill_value Returns the maximum filling value for a given datatype. Examples -------- >>> import numpy.ma as ma >>> x = [[-1., 2.5], [4., -2.], [3., 0.]] >>> mask = [[0, 0], [1, 0], [1, 0]] >>> masked_x = ma.masked_array(x, mask) >>> masked_x masked_array( data=[[-1.0, 2.5], [--, -2.0], [--, 0.0]], mask=[[False, False], [ True, False], [ True, False]], fill_value=1e+20) >>> ma.max(masked_x) 2.5 >>> ma.max(masked_x, axis=0) masked_array(data=[-1.0, 2.5], mask=[False, False], fill_value=1e+20) >>> ma.max(masked_x, axis=1, keepdims=True) masked_array( data=[[2.5], [-2.0], [0.0]], mask=[[False], [False], [False]], fill_value=1e+20) >>> mask = [[1, 1], [1, 1], [1, 1]] >>> masked_x = ma.masked_array(x, mask) >>> ma.max(masked_x, axis=1) masked_array(data=[--, --, --], mask=[ True, True, True], fill_value=1e+20, dtype=float64) r!Nr rrrr)rr rqr"rrNrrlr^rrwrrMrwr!rrYrrurrrr(rrrs rrzMaskedArray.maxsP 2;..Z4J "5$99&99  +D11J ;0T[[,,0.s..&,...2d4::.>.> { ""7+++<HIff&7wGGGG M,Z((,J$CJJ6JJ c; ' ' 2cllG&  &4SY&?&??#)"GLLy~&&&''' Ic26 1 1 1 1 rc|5||||}|||||z}|S||||||_||||}tj|||d|S)a Return (maximum - minimum) along the given dimension (i.e. peak-to-peak value). .. warning:: `ptp` preserves the data type of the array. This means the return value for an input of signed integers with n bits (e.g. `np.int8`, `np.int16`, etc) is also a signed integer with n bits. In that case, peak-to-peak values greater than ``2**(n-1)-1`` will be returned as negative values. An example with a work-around is shown below. Parameters ---------- axis : {None, int}, optional Axis along which to find the peaks. If None (default) the flattened array is used. out : {None, array_like}, 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. fill_value : scalar or None, optional Value used to fill in the masked values. 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 array. Returns ------- ptp : ndarray. A new array holding the result, unless ``out`` was specified, in which case a reference to ``out`` is returned. Examples -------- >>> x = np.ma.MaskedArray([[4, 9, 2, 10], ... [6, 9, 7, 12]]) >>> x.ptp(axis=1) masked_array(data=[8, 6], mask=False, fill_value=999999) >>> x.ptp(axis=0) masked_array(data=[2, 0, 5, 2], mask=False, fill_value=999999) >>> x.ptp() 10 This example shows that a negative value can be returned when the input is an array of signed integers. >>> y = np.ma.MaskedArray([[1, 127], ... [0, 127], ... [-1, 127], ... [-2, 127]], dtype=np.int8) >>> y.ptp(axis=1) masked_array(data=[ 126, 127, -128, -127], mask=False, fill_value=999999, dtype=int8) A work-around is to use the `view()` method to view the result as unsigned integers with the same bit width: >>> y.ptp(axis=1).view(np.uint8) masked_array(data=[126, 127, 128, 129], mask=False, fill_value=999999, dtype=uint8) N)rrMr!)rrtrMr!rr)rrrrr)r}rrtrMr!rU min_values rrzMaskedArray.ptpIsV ;XX4J'/11F dhhDZ(022 2FM883:%-//HH$:&.00  CX>>>> rc~tjd|jjddt j|i|S)Nz3Warning: 'partition' will ignore the 'mask' of the r0rr)rrrrr partitionr}rrrs rrzMaskedArray.partitionsY ; $ 7;;;!" $ $ $ $!uww $1&111rc~tjd|jjddt j|i|S)Nz6Warning: 'argpartition' will ignore the 'mask' of the r0rr)rrrrr argpartitionrs rrzMaskedArray.argpartitionsY ; $ 7;;;!" $ $ $ $$uww#T4V444rc|j|j}}t|}t|}|tur|d}|2||||d|}ntj|||||t|tr>|tur|} n||||} | |z} | | |dS)z rN)rr.)rrrtr) rjrqr^rYrrNrrlrr!rrw) r}rarrtrrjrqre maskindicesrs rrzMaskedArray.takes*dj4jjg&& f $ $nnQ''G ;**W4d*;;C@EEcJJCC GE7Dc B B B B c; ' ' %%**W4d*CC;& OOG $ $ $2wrr=rFflattenrrrc*|Sr)rrs rzMaskedArray.s4>>#3#3rrcL|j}|tur|jS|'||S|jj}|rN|jd|D}|D]}d||||<|S|turdgS|j}tj |j t}d|| <||_|S)aP Return the data portion of the masked array as a hierarchical Python list. Data items are converted to the nearest compatible Python type. Masked values are converted to `fill_value`. If `fill_value` is None, the corresponding entries in the output list will be ``None``. Parameters ---------- fill_value : scalar, optional The value to use for invalid entries. Default is None. Returns ------- result : list The Python list representation of the masked array. Examples -------- >>> x = np.ma.array([[1,2,3], [4,5,6], [7,8,9]], mask=[0] + [1,0]*4) >>> x.tolist() [[1, None, 3], [None, 5, None], [7, None, 9]] >>> x.tolist(-999) [[1, -999, 3], [-999, 5, -999], [7, -999, 9]] Nc g|] }|tf Sr)rJrs rrz&MaskedArray.tolist..s'C'C'CF 'C'C'Crr) rqrrjtolistrNrrrrrr rrJ)r}rMrqrrUrrss rrzMaskedArray.tolists6  F??:$$&& &  !;;z**1133 3    #Z&&'C'CU'C'C'CDDF + +&*q %(##==?? " F??6M:$***,,F;;; $u{{}} }}rchtjdtd|||S)z A compatibility alias for `tobytes`, with exactly the same behavior. Despite its name, it returns `bytes` not `str`\ s. .. deprecated:: 1.19.0 z0tostring() is deprecated. Use tobytes() instead.rrr)rrrtobytesr}rMrs rtostringzMaskedArray.tostrings=  > 1 . . . .||Je|444rcT|||S)a Return the array data as a string containing the raw bytes in the array. The array is filled with a fill value before the string conversion. .. versionadded:: 1.9.0 Parameters ---------- fill_value : scalar, optional Value used to fill in the masked values. Default is None, in which case `MaskedArray.fill_value` is used. order : {'C','F','A'}, optional Order of the data item in the copy. Default is 'C'. - 'C' -- C order (row major). - 'F' -- Fortran order (column major). - 'A' -- Any, current order of array. - None -- Same as 'A'. See Also -------- numpy.ndarray.tobytes tolist, tofile Notes ----- As for `ndarray.tobytes`, information about the shape, dtype, etc., but also about `fill_value`, will be lost. Examples -------- >>> x = np.ma.array(np.array([[1, 2], [3, 4]]), mask=[[0, 1], [1, 0]]) >>> x.tobytes() b'\x01\x00\x00\x00\x00\x00\x00\x00?B\x0f\x00\x00\x00\x00\x00?B\x0f\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00' r)rNr r s rr zMaskedArray.tobytess(L{{:&&..U.;;;rr%sc td)z Save a masked array to a file in binary format. .. warning:: This function is not implemented yet. Raises ------ NotImplementedError When `tofile` is called. z)MaskedArray.tofile() not implemented yet.r)r}fidsepr(s rtofilezMaskedArray.tofile;s""MNNNrc|j}|j}|t|j|}|jj}t j|jd|fd|fg}|j|d<|j|d<|S)a Transforms a masked array into a flexible-type array. The flexible type array that is returned will have two fields: * the ``_data`` field stores the ``_data`` part of the array. * the ``_mask`` field stores the ``_mask`` part of the array. Parameters ---------- None Returns ------- record : ndarray A new flexible-type `ndarray` with two fields: the first element containing a value, the second element containing the corresponding mask boolean. The returned record shape matches self.shape. Notes ----- A side-effect of transforming a masked array into a flexible `ndarray` is that meta information (``fill_value``, ...) will be lost. Examples -------- >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4) >>> x masked_array( data=[[1, --, 3], [--, 5, --], [7, --, 9]], mask=[[False, True, False], [ True, False, True], [False, True, False]], fill_value=999999) >>> x.toflex() array([[(1, False), (2, True), (3, False)], [(4, True), (5, False), (6, True)], [(7, False), (8, True), (9, False)]], dtype=[('_data', 'X333" H) $ $ $E 8 # # #D $$X$ [[& & X& P%%%%& _N_NNNNN`6FFFFP>000R%R%R%h ' ' 'CCCJ 4 4 4 4 4 4444444444444      %%%%%%%%% %%%###(((((())))))""""""$""&&&* " " "    X0yH X0yH a<a<a<aDdR[555555n#/#/#/#/J4T[======|&.CK4T[02;TNANANANA`-:-:-:-:-:-:^%:%:%:%:%:%:N.2&*Q>Q>Q>Q>f$aaaaF$iiiiVVVVVp22222 55555 6 <  D|J''Hl9%%G \( # #Fl9%%G|J''H33444A [))I1111f 5 5 5 5&<&<&<&">">r"BEKKKC  !)E  s!A;;:B87B8c6tjdS)Nr)rrjrs rrjz mvoid._datasww}R  rc|j}t||tr4t|j||||j||jS|tur||rtS|j|S)z! Get the index. )rmrorMr) rqr!rrxrjrrrrw)r}rrs rrzmvoid.__getitem__s J agw ' ' * Z%AdG+D1.*** * F??qw?Mz$rc||j|<|jr&|j|xxt|ddzcc<dSt|dd|j|<dS)NrqF)rjrrqr)r}rr-s rrzmvoid.__setitem__sf  4 > > Jt   w > > >     &ugu==DJt   rc$|j}|turt|jSt |jjd}t j}||}t||jtt|S)Nr) rqrr+rjrrrrr]r)r}rrdata_arrrIrs rrz mvoid.__str__sq J ;;tz?? "&tz'7==77=oof%%sDJ0CDDD3xxrc#K|j|j}}|tur |Ed{VdSt||D]\}}|r tV|VdS)zDefines an iterator for mvoidN)rjrqrr=rw)r}rjrqrrs rrzmvoid.__iter__ s*dj F??         eU++  A LLLLGGGG   rc4|jSr)rj__len__rs rrJz mvoid.__len__sz!!###rcRt||dS)aA Return a copy with masked fields filled with a given value. Parameters ---------- fill_value : array_like, optional The value to use for invalid entries. Can be scalar or non-scalar. If latter is the case, the filled array should be broadcastable over input array. Default is None, in which case the `fill_value` attribute is used instead. Returns ------- filled_void A `np.void` object See Also -------- MaskedArray.filled r)r0rN)r}rMs rrNz mvoid.filleds#,t}}##J//33rc4|j}|tur|jSg}t |j|jD]D\}}|r|d||Et|S)z Transforms the mvoid object into a tuple. Masked fields are replaced by None. Returns ------- returned_tuple Tuple of fields N)rqrrjrr=r"r?r)r}rqrUrrs rrz mvoid.tolist3s  F??:$$&& &$*dj11 ( (FQ ( d#### affhh''''V}}rr)rrrrrrr6rjrrrr[rrJrNrrrs@rrrs"(tU$(!!!!X!   ,>>>     H   $$$44440rrc,t|tS)a Test whether input is an instance of MaskedArray. This function returns True if `x` is an instance of MaskedArray and returns False otherwise. Any object is accepted as input. Parameters ---------- x : object Object to test. Returns ------- result : bool True if `x` is a MaskedArray. See Also -------- isMA : Alias to isMaskedArray. isarray : Alias to isMaskedArray. Examples -------- >>> import numpy.ma as ma >>> a = np.eye(3, 3) >>> a array([[ 1., 0., 0.], [ 0., 1., 0.], [ 0., 0., 1.]]) >>> m = ma.masked_values(a, 0) >>> m masked_array( data=[[1.0, --, --], [--, 1.0, --], [--, --, 1.0]], mask=[[False, True, True], [ True, False, True], [ True, True, False]], fill_value=0.0) >>> ma.isMaskedArray(a) False >>> ma.isMaskedArray(m) True >>> ma.isMaskedArray([0, 1, 2]) False )r!rrs rrerePs` a % %%rceZdZdZedZdZfdZddZddZ dZ dZ d Z d Z d ZexZxZxZxZxZZ[d Zd ZdZfdZxZS)r`Nc@|jduot|j|uSr)_MaskedConstant__singletonr^)res r__has_singletonzMaskedConstant.__has_singletons%d*KtCO/D/D/KKrc |sitjd}tjd}d|j_d|j_t ||||_|jS)NrTFr)_MaskedConstant__has_singletonrr r writeablerrlrQ)rermros rrzMaskedConstant.__new__su""$$ E8B<>D$)DJ #(DJ *$T:::??DDCOrc|s!t|S||jurdSt|_t||dSr)rTrrrQrr)r}rrs rrz!MaskedConstant.__array_finalize__si##%% 677--c22 2 T% % % D)DN  * *4 5 5 5 5 5rc^|t||Sr)rlr__array_prepare__r}rrs rrXz MaskedConstant.__array_prepare__s$yy%%77WEEErc^|t||Sr)rlrrrYs rrzMaskedConstant.__array_wrap__s$yy%%44S'BBBrc4ttjSr)r+rrMrs rrzMaskedConstant.__str__s&/000rcV|tjurdSt|S)Nrw)r`rQrJr[rs rr[zMaskedConstant.__repr__s) >- - -8??4(( (rc t||S#t$r:tjdt dt|dcYSwxYw)NzjFormat strings passed to MaskedConstant are ignored, but in future may error or produce different behaviorrrr)rJ __format__rrr FutureWarning)r} format_specs rr^zMaskedConstant.__format__sy /$$T;77 7 / / / M6!     $$T2.. . . . /sAA! A!c|jdfS)z.Override of MaskedArray's __reduce__. rrrs rrzMaskedConstant.__reduce__s##rc|SrrrRs r__iop__zMaskedConstant.__iop__rrc|S)z: Copy is a no-op on the maskedconstant, as it is a scalar r)r}rrs rr=zMaskedConstant.copys  rc|Srrrs r__copy__zMaskedConstant.__copy__rrc|Srr)r}r*s rr-zMaskedConstant.__deepcopy__rrc|s"t||S||jurt d|dt||S)Nzattributes of z are not writeable)rTr __setattr__rQrk)r}attrr-rs rrizMaskedConstant.__setattr__s{##%% 477&&tU33 3 T% % % ;;;;== = 77&&tU33 3rr)rrrrQ classmethodrTrrrXrrr[r^rrcrrrrrrr=rfr-rirrs@rr`r`s_KLL[L $ 6 6 6 6 6FFFFCCCC111))) / / /$$$  H     4 4 4 4 4 4 4 4 4rr`c 6t||||| |||| || S)z~ Shortcut to MaskedArray. The options are in a different order for convenience and backwards compatibility. ) rorr=rirrrMrrr)r) rmrr=rrorMrrrrirs rr r s8 t$e$"i!*z"6 @ @ @@rcft|}|turdS|rdSdS)a Determine whether input has masked values. Accepts any object as input, but always returns False unless the input is a MaskedArray containing masked values. Parameters ---------- x : array_like Array to check for masked values. Returns ------- result : bool True if `x` is a MaskedArray with masked values, False otherwise. Examples -------- >>> import numpy.ma as ma >>> x = ma.masked_equal([0, 1, 0, 2, 3], 0) >>> x masked_array(data=[--, 1, --, 2, 3], mask=[ True, False, True, False, False], fill_value=0) >>> ma.is_masked(x) True >>> x = ma.masked_equal([0, 1, 0, 2, 3], 42) >>> x masked_array(data=[0, 1, 0, 2, 3], mask=False, fill_value=42) >>> ma.is_masked(x) False Always returns False if `x` isn't a MaskedArray. >>> x = [False, True, False] >>> ma.is_masked(x) False >>> x = 'a string' >>> ma.is_masked(x) False FT)rYrr!)rrs rrgrgs8Z  AF{{u t 5rcBeZdZdZfdZdZejfdZdZ xZ S)_extrema_operationz Generic class for maximum/minimum functions. .. note:: This is the base class for `_maximum_operation` and `_minimum_operation`. cft|||_||_dSr)rr~rHfill_value_func)r}rrHrMrs rr~z_extrema_operation.__init__Ss0  )rcLt|||||S)r)rrHr|s rrz_extrema_operation.__call__Xs$T\\!Q''A...rct|dd}t|}|tjur:|jdkr/t jd|jd|jdtd d }|tjurt| }nt}|tur|j j |fi|}n| ||t!|}|j j |fi|}t#jj |fi|}t'|d r||_n |rt*}|S) z#Reduce target along the given axis.FTrhrz!In the future the default for ma.z:.reduce will be axis=0, not the current None, to match np.z;.reduce. Explicitly pass 0 or None to silence this warning.rrNrrq)rrYrr rrrrrr[rrrrNrqrlr^rror"rqrw)r}rrrrrs rrz_extrema_operation.reduce]stU$777 FOO 2;  6;?? MEDMEE59]EEE)Q  8 8 8 8 D r{ " "t___FFVVF ;; f////AA]]$$V,,...2d4<<.@.@  f////A!(55f55Aq'""  rct|}t|}|tur|turt}n9t|}t|}t||}|jt |t |}t|ts| t}||_ |S)z$>>    74D999;CJ  rc|jrt|}|d|c}|d<t|}|j}t t ||d}|t t |}||g|Ri|Sr)rrur/rrr^r)r}rSrrxmarr method_namemethods rrz_frommethod.__call__s = $::Da!JAtAw!}}m d[$77 >R--Fvd,T,,,V,,,rNr.)rrrrr~rrrrrr~r~sP!!!!  - - - - -rr~rrr!r8)rrBrCr=rFr]r`rrrrrrErrrrrrrArcRt|}|||||S)z )rrtr)rxr)rSrarrtrs rrrs) QA 66'#D6 9 99rc |tdt|}t|}t||}t|}t|}t |t rt |}nt }tjdd5tj ||tj || |} dddn #1swxYwY| |tjtj| t } |t"ur(| jst&Stj|| | _| r2| jst&S| jt"ur| | _| j| j| <| S)a Returns element-wise base array raised to power from second array. This is the masked array version of `numpy.power`. For details see `numpy.power`. See Also -------- numpy.power Notes ----- The *out* argument to `numpy.power` is not supported, `third` has to be None. Examples -------- >>> import numpy.ma as ma >>> x = [11.2, -3.973, 0.801, -1.41] >>> mask = [0, 0, 0, 1] >>> masked_x = ma.masked_array(x, mask) >>> masked_x masked_array(data=[11.2, -3.973, 0.801, --], mask=[False, False, False, True], fill_value=1e+20) >>> ma.power(masked_x, 2) masked_array(data=[125.43999999999998, 15.784728999999999, 0.6416010000000001, --], mask=[False, False, False, True], fill_value=1e+20) >>> y = [-0.5, 2, 0, 17] >>> masked_y = ma.masked_array(y, mask) >>> masked_y masked_array(data=[-0.5, 2.0, 0.0, --], mask=[False, False, False, True], fill_value=1e+20) >>> ma.power(masked_x, masked_y) masked_array(data=[0.29880715233359845, 15.784728999999999, 1.0, --], mask=[False, False, False, True], fill_value=1e+20) Nz3-argument power not supported.rr)rrYrvrXr!rr^rrrrrrlrrprprrrrwrqrqr!rMrj) rSrthirdrrrfafbr@rUrrs rrrsV 9::: B BBA B B![!!77 Hh 7 7 7EE!RR!4!455::8DDEEEEEEEEEEEEEEE nR[W)=)=>>??G{ M}Q00 {{}}2{ #M \V # #"FL & 1 W Ms =C))C-0C-r,r+ctj|}|tjurt|}t |t r||||||S||||S)z)Function version of the eponymous method.rr(rrrMr)rr/r rr!rr-rSrr(rrrMs rr-r-Ts aA r{&q))![!!<yydU!(ZAA AyydUy;;;rrctj|dd}||}d}t|tr||||||n|||||S)a Return a sorted copy of the masked array. Equivalent to creating a copy of the array and applying the MaskedArray ``sort()`` method. Refer to ``MaskedArray.sort`` for the full documentation See Also -------- MaskedArray.sort : equivalent method Examples -------- >>> import numpy.ma as ma >>> x = [11.2, -3.973, 0.801, -1.41] >>> mask = [0, 0, 0, 1] >>> masked_x = ma.masked_array(x, mask) >>> masked_x masked_array(data=[11.2, -3.973, 0.801, --], mask=[False, False, False, True], fill_value=1e+20) >>> ma.sort(masked_x) masked_array(data=[-3.973, 0.801, 11.2, --], mask=[False, False, False, True], fill_value=1e+20) TrhNrrr)rr rr!rrrs rrrcs8 T***A | IIKK![!!2 Dt5:  7 7 7 7 Dt5111 HrcDt|S)ag Return all the non-masked data as a 1-D array. This function is equivalent to calling the "compressed" method of a `ma.MaskedArray`, see `ma.MaskedArray.compressed` for details. See Also -------- ma.MaskedArray.compressed : Equivalent method. Examples -------- Create an array with negative values masked: >>> import numpy as np >>> x = np.array([[1, -1, 0], [2, -1, 3], [7, 4, -1]]) >>> masked_x = np.ma.masked_array(x, mask=x < 0) >>> masked_x masked_array( data=[[1, --, 0], [2, --, 3], [7, 4, --]], mask=[[False, True, False], [False, True, False], [False, False, True]], fill_value=999999) Compress the masked array into a 1-D array of non-masked values: >>> np.ma.compressed(masked_x) array([1, 0, 2, 3, 7, 4]) )r/r9rNs rr9r9sF a== # # % %%rcXtjd|D|}t|}||}|D]}t |t urn|Stjd|D|}||j}t||_ |S)aI Concatenate a sequence of arrays along the given axis. Parameters ---------- arrays : sequence of array_like The arrays must have the same shape, except in the dimension corresponding to `axis` (the first, by default). axis : int, optional The axis along which the arrays will be joined. Default is 0. Returns ------- result : MaskedArray The concatenated array with any masked entries preserved. See Also -------- numpy.concatenate : Equivalent function in the top-level NumPy module. Examples -------- >>> import numpy.ma as ma >>> a = ma.arange(3) >>> a[1] = ma.masked >>> b = ma.arange(2, 5) >>> a masked_array(data=[0, --, 2], mask=[False, True, False], fill_value=999999) >>> b masked_array(data=[2, 3, 4], mask=False, fill_value=999999) >>> ma.concatenate([a, b]) masked_array(data=[0, --, 2, 2, 3, 4], mask=[False, True, False, False, False, False], fill_value=999999) c,g|]}t|Sr)rXr_s rrzconcatenate..s333q 333rc,g|]}t|Srrr_s rrzconcatenate..s999Qa999r) rr:rfrlrYrrrrrq)rbrrrcrmrdms rr:r:sR 33F333T::A  'D 66$<>> import numpy as np >>> x = np.array([[11.2, -3.973, 18], [0.801, -1.41, 12], [7, 33, -12]]) >>> masked_x = np.ma.masked_array(x, mask=x < 0) >>> masked_x masked_array( data=[[11.2, --, 18.0], [0.801, --, 12.0], [7.0, 33.0, --]], mask=[[False, True, False], [False, True, False], [False, False, True]], fill_value=1e+20) Isolate the main diagonal from the masked array: >>> np.ma.diag(masked_x) masked_array(data=[11.2, --, --], mask=[False, True, True], fill_value=1e+20) Isolate the first diagonal below the main diagonal: >>> np.ma.diag(masked_x, -1) masked_array(data=[0.801, 33.0], mask=[False, False], fill_value=1e+20) )rrErlrrYrrq)r,rr3s rrErEsMXWQ]]   , ,Fqzzwqw** Mrct|}|tur1tjt ||}t |Stjt |d|}t ||S)z Shift the bits of an integer to the left. This is the masked array version of `numpy.left_shift`, for details see that function. See Also -------- numpy.left_shift rr)rYrrrirNrxrSrrrs rriri si  AF{{  VAYY * *A  VAq\\1 - -AA&&&&rct|}|tur1tjt ||}t |Stjt |d|}t ||S)a Shift the bits of an integer to the right. This is the masked array version of `numpy.right_shift`, for details see that function. See Also -------- numpy.right_shift Examples -------- >>> import numpy.ma as ma >>> x = [11, 3, 8, 1] >>> mask = [0, 0, 0, 1] >>> masked_x = ma.masked_array(x, mask) >>> masked_x masked_array(data=[11, 3, 8, --], mask=[False, False, False, True], fill_value=999999) >>> ma.right_shift(masked_x,1) masked_array(data=[5, 1, 4, --], mask=[False, False, False, True], fill_value=999999) rr)rYrrrrNrxrs rrr5si6  AF{{  fQii + +A  fQllA . .AA&&&&rc ||||S#t$r*t|d|||cYSwxYw)z Set storage-indexed locations to corresponding values. This function is equivalent to `MaskedArray.put`, see that method for details. See Also -------- MaskedArray.put rFr)rrkr)rSrarrs rrrYsmEuuWf4u000 EEEae$$$((&t(DDDDDEs1A Act|ts|t}t|t |}}t |t urL|t urBd|_t|j|j |_ tj |j ||n|j rJ|t ur@|j }tj ||||xj|zc_n4|t urt!|}tj |j ||tj |j||dS)aQ Changes elements of an array based on conditional and input values. This is the masked array version of `numpy.putmask`, for details see `numpy.putmask`. See Also -------- numpy.putmask Notes ----- Using a masked array as `values` will **not** transform a `ndarray` into a `MaskedArray`. TrN)r!rrlrXrYrrrurrrqrrrr=rorZrj)rSrorvaldatavalmaskrs rrrls($ a % % FF;  !&//76??gWqzzV &  AM$QWag66AG Iagwd 3 3 3 3 0 &  A Ia - - - - FFaKFF f  "6**G !'7$////Iagwd++++ Frc ||S#t$r?t|d|tcYSwxYw)a Permute the dimensions of an array. This function is exactly equivalent to `numpy.transpose`. See Also -------- numpy.transpose : Equivalent function in top-level NumPy module. Examples -------- >>> import numpy.ma as ma >>> x = ma.arange(4).reshape((2,2)) >>> x[1, 1] = ma.masked >>> x masked_array( data=[[0, 1], [2, --]], mask=[[False, False], [False, True]], fill_value=999999) >>> ma.transpose(x) masked_array( data=[[0, 2], [1, --]], mask=[[False, False], [False, True]], fill_value=999999) Fr)rrkrrlr)rSrs rrrso@G{{4   GGGae$$$..t4499+FFFFFGsAA A rc |||S#t$rCt|d||}|tcYSwxYw)z Returns an array containing the same data with a new shape. Refer to `MaskedArray.reshape` for full documentation. See Also -------- MaskedArray.reshape : equivalent function rFr)rrkrrlr)rS new_shaper_tmps rrrsu&yy%y000 &&&ae$$$,,Ye,DDyy%%%%%&sA A&%A&ct|}|turtj||}tj||t |}|jr||_|S)a Return a new masked array with the specified size and shape. This is the masked equivalent of the `numpy.resize` function. The new array is filled with repeated copies of `x` (in the order that the data are stored in memory). If `x` is masked, the new array will be masked, and the new mask will be a repetition of the old one. See Also -------- numpy.resize : Equivalent function in the top level NumPy module. Examples -------- >>> import numpy.ma as ma >>> a = ma.array([[1, 2] ,[3, 4]]) >>> a[0, 1] = ma.masked >>> a masked_array( data=[[1, --], [3, 4]], mask=[[False, True], [False, False]], fill_value=999999) >>> np.resize(a, (3, 3)) masked_array( data=[[1, 2, 3], [4, 1, 2], [3, 4, 1]], mask=False, fill_value=999999) >>> ma.resize(a, (3, 3)) masked_array( data=[[1, --, 3], [4, 1, --], [3, 4, 1]], mask=[[False, True, False], [False, False, True], [False, False, False]], fill_value=999999) A MaskedArray is always returned, regardless of the input type. >>> a = np.array([[1, 2] ,[3, 4]]) >>> ma.resize(a, (3, 3)) masked_array( data=[[1, 2, 3], [4, 1, 2], [3, 4, 1]], mask=False, fill_value=999999) )rYrrrrlrfrrq)rrrrUs rrrshn  A Ia # # Yq) $ $ ) )*=a*@*@ A AF { MrcDtjt|S)z5 maskedarray version of the numpy function. )rrrXr#s rrr s 773<<  rcDtjt|S*maskedarray version of the numpy function.)rrrXr#s rrrs 8GCLL ! !!rcFtjt||Sr)rrrX)rrs rrrs 773<< & &&rc|dkr|S|dkrtdt|ztj|}|jdkrtdg}|tjurztj|}|jdkr;t|j}d||<tj |t|}| || ||tjurztj|}|jdkr;t|j}d||<tj |t|}| |t|dkr tj ||}tj|||S)a Calculate the n-th discrete difference along the given axis. The first difference is given by ``out[i] = a[i+1] - a[i]`` along the given axis, higher differences are calculated by using `diff` recursively. Preserves the input mask. Parameters ---------- a : array_like Input array n : int, optional The number of times values are differenced. If zero, the input is returned as-is. axis : int, optional The axis along which the difference is taken, default is the last axis. prepend, append : array_like, optional Values to prepend or append to `a` along axis prior to performing the difference. Scalar values are expanded to arrays with length 1 in the direction of axis and the shape of the input array in along all other axes. Otherwise the dimension and shape must match `a` except along axis. Returns ------- diff : MaskedArray The n-th differences. The shape of the output is the same as `a` except along `axis` where the dimension is smaller by `n`. The type of the output is the same as the type of the difference between any two elements of `a`. This is the same as the type of `a` in most cases. A notable exception is `datetime64`, which results in a `timedelta64` output array. See Also -------- numpy.diff : Equivalent function in the top-level NumPy module. Notes ----- Type is preserved for boolean arrays, so the result will contain `False` when consecutive elements are the same and `True` when they differ. For unsigned integer arrays, the results will also be unsigned. This should not be surprising, as the result is consistent with calculating the difference directly: >>> u8_arr = np.array([1, 0], dtype=np.uint8) >>> np.ma.diff(u8_arr) masked_array(data=[255], mask=False, fill_value=999999, dtype=uint8) >>> u8_arr[1,...] - u8_arr[0,...] 255 If this is not desirable, then the array should be cast to a larger integer type first: >>> i16_arr = u8_arr.astype(np.int16) >>> np.ma.diff(i16_arr) masked_array(data=[-1], mask=False, fill_value=999999, dtype=int16) Examples -------- >>> a = np.array([1, 2, 3, 4, 7, 0, 2, 3]) >>> x = np.ma.masked_where(a < 2, a) >>> np.ma.diff(x) masked_array(data=[--, 1, 1, 3, --, --, 1], mask=[ True, False, False, False, True, True, False], fill_value=999999) >>> np.ma.diff(x, n=2) masked_array(data=[--, 0, 2, --, --, --], mask=[ True, False, False, True, True, True], fill_value=999999) >>> a = np.array([[1, 3, 1, 5, 10], [0, 1, 5, 6, 8]]) >>> x = np.ma.masked_equal(a, value=1) >>> np.ma.diff(x) masked_array( data=[[--, --, --, 5], [--, --, 1, 2]], mask=[[ True, True, True, False], [ True, True, False, False]], fill_value=1) >>> np.ma.diff(x, axis=0) masked_array(data=[[--, --, --, 1, -2]], mask=[[ True, True, True, False, False]], fill_value=1) rz#order must be non-negative but got z4diff requires input that is at least one dimensionalr)rIr1rrr/rr rurrGrr"r<r:rG)rSrrprependr"combinedrs rrGrG"sD Avv1uu>aHIII Av{{ B Hbk!!%""7++ <1  MMEE$KoguU||<>> x = np.ma.array(np.arange(9.).reshape(3, 3), mask=[[0, 1, 0], ... [1, 0, 1], ... [0, 1, 0]]) >>> x masked_array( data=[[0.0, --, 2.0], [--, 4.0, --], [6.0, --, 8.0]], mask=[[False, True, False], [ True, False, True], [False, True, False]], fill_value=1e+20) >>> np.ma.where(x > 5, x, -3.1416) masked_array( data=[[-3.1416, --, -3.1416], [--, -3.1416, --], [6.0, --, 8.0]], mask=[[False, True, False], [ True, False, True], [False, True, False]], fill_value=1e+20) Trz)Must provide both 'x' and 'y' or neither.rFrrr)r rArIrrNrXrZrwrrrrrrrx) r'rrmissingrxdydcmxmymrmros rrrspH}a8m,22488G!||DEEE!||y!!!  5 ! !B B B i B aB aB F{{q Xb ) ) ) WR ) ) ) f& Xb ) ) ) WR ) ) ) 8BB  D 8BB  D 8B$*555t < >> choice = np.array([[1,1,1], [2,2,2], [3,3,3]]) >>> a = np.array([2, 1, 0]) >>> np.ma.choose(a, choice) masked_array(data=[3, 2, 1], mask=False, fill_value=999999) c6|turdSt|S)z,Returns the filled array, or True if masked.T)rwrNrNs rfmaskzchoose..fmask6s ;;4ayyrc6|turdSt|S)z:Returns the mask, True if ``masked``, False if ``nomask``.T)rwrYrNs rnmaskzchoose..nmask<s ;;4qzzrrc&g|] }|Srr)rrrs rrzchoose..Ds! ' ' '!UU1XX ' ' 'rc&g|] }|Srr)rrrs rrzchoose..Es! & & &EE!HH & & &rrFTr )rrt) rNrr5rsrvrYrlrr!rw) rachoicesrtrrmasksrm outputmaskrrrs @@rr5r5 sZ  wA ' ' ' 'w ' ' 'E & & & &g & & &D1e$///J7:ww/?/?@@ %d444J !T#...33K@@A  c; ' ' ( OOJ ' ' ' MM* Hrc|tj|||Stjt|||t|drt ||_|S)a Return a copy of a, rounded to 'decimals' places. When 'decimals' is negative, it specifies the number of positions to the left of the decimal point. The real and imaginary parts of complex numbers are rounded separately. Nothing is done if the array is not of float type and 'decimals' is greater than or equal to 0. Parameters ---------- decimals : int Number of decimals to round to. May be negative. out : array_like Existing array to use for output. If not given, returns a default copy of a. Notes ----- If out is given and does not have a mask attribute, the mask of a is lost! Examples -------- >>> import numpy.ma as ma >>> x = [11.2, -3.973, 0.801, -1.41] >>> mask = [0, 0, 0, 1] >>> masked_x = ma.masked_array(x, mask) >>> masked_x masked_array(data=[11.2, -3.973, 0.801, --], mask=[False, False, False, True], fill_value=1e+20) >>> ma.round_(masked_x) masked_array(data=[11.0, -4.0, 1.0, --], mask=[False, False, False, True], fill_value=1e+20) >>> ma.round(masked_x, decimals=1) masked_array(data=[11.2, -4.0, 0.8, --], mask=[False, False, False, True], fill_value=1e+20) >>> ma.round_(masked_x, decimals=-1) masked_array(data=[10.0, -0.0, 0.0, --], mask=[False, False, False, True], fill_value=1e+20) Nrq)rrrXr"rYrq)rSrrts rrrTs\\ {yHc*** '!**h,,, 3  # CI rcBt|d}t|}|tus|r||S|j|_t ||j}|D]'}|xj||dzc_(|S)zH Mask whole 1-d vectors of an array that contain masked values. FrBNT)rr!)r rYrr!rqr=rr)rSrrrrs r_mask_propagaters auA AF{{!%%''{T\gllnnAG af - -D11 155b45000 Hrc:|durtj|dkstj|dkrnl|jdkr1t||jdz }t||jdz }n0t||jdz }t||jdz }t|}t|}|tjt |dt |d}tj||}tj|dkrtj|}|t||}| ||Stjt |dt |d|j }|j j |j kr$tj |j t|_tj|||jtj|j|j|S)aU Return the dot product of two arrays. This function is the equivalent of `numpy.dot` that takes masked values into account. Note that `strict` and `out` are in different position than in the method version. In order to maintain compatibility with the corresponding method, it is recommended that the optional arguments be treated as keyword only. At some point that may be mandatory. Parameters ---------- a, b : masked_array_like 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. out : masked_array, optional Output argument. This must have the exact kind that would be returned if it was not used. In particular, it must have the right type, must be C-contiguous, and its dtype must be the dtype that would be returned for `dot(a,b)`. This is a performance feature. Therefore, if these conditions are not met, an exception is raised, instead of attempting to be flexible. .. versionadded:: 1.10.2 See Also -------- numpy.dot : Equivalent function for ndarrays. Examples -------- >>> a = np.ma.array([[1, 2, 3], [4, 5, 6]], mask=[[1, 0, 0], [0, 0, 0]]) >>> b = np.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) Trrr)rrrrZrrNr0rlrfrwrjrorrIrrqrp) rSrrrtambmrrrs rrrsj~~ 71::??bgajjAoo  Vq[[16A:..A16A:..AA16A:..A16A:..A q// B q// B { F6!Q<<1 . . VB^^O 71::?? 1 A FF&q!,, - - a F6!Q<<1sy 9 9 8>QW $ $(33CI r2sy!!! sy#),,, rct|d}t|d}|jdkrd|_|jdkrd|_tj||t S)z Returns the inner product of a and b for arrays of floating point types. Like the generic NumPy equivalent the product sum is over the last dimension of a and b. The first argument is not conjugated. rr)rNrrrrbrlr)rSrrrs rrbrbsb 1B 1B w!|| w!|| 8B    - --rz Masked values are replaced by 0.ct|d}t|d}tj||}t |}t |}|t ur|t urt |St|}t|}tdtjd|z d|z z d}t ||S)rrrFrr) rNrrrrYrrxrZrs)rSrrrrrrrs rrrs 1    B 1    B RA B B V||f A aB aB!bhq2vq2v...U;;;A  " " ""rc:|r|t|tjtj|t||tjtj|tt||z}|t |t ||}nS|t|t|}|t |dt |d|}t||S)z: Helper function for ma.correlate and ma.convolve rrrr)rZrrrrrXrNrx)rrSr,rpropagate_maskrorms r_convolve_or_correlaters 8 Al1oorwrx{{$???d K K K Abgbhqkk... Qd K K K L qWQZZd333<??"\!__$4555q1va||$777 4 ( ( ((rvalidc<ttj||||S)a Cross-correlation of two 1-dimensional sequences. Parameters ---------- a, v : array_like Input sequences. mode : {'valid', 'same', 'full'}, optional Refer to the `np.convolve` docstring. Note that the default is 'valid', unlike `convolve`, which uses 'full'. propagate_mask : bool If True, then a result element is masked if any masked element contributes towards it. If False, then a result element is only masked if no non-masked element contribute towards it Returns ------- out : MaskedArray Discrete cross-correlation of `a` and `v`. See Also -------- numpy.correlate : Equivalent function in the top-level NumPy module. )rrr>rSr,rrs rr>r>)s2 "",1dN K KKrrc<ttj||||S)a Returns the discrete, linear convolution of two one-dimensional sequences. Parameters ---------- a, v : array_like Input sequences. mode : {'valid', 'same', 'full'}, optional Refer to the `np.convolve` docstring. propagate_mask : bool If True, then if any masked element is included in the sum for a result element, then the result is masked. If False, then the result element is only masked if no non-masked cells contribute towards it Returns ------- out : MaskedArray Discrete, linear convolution of `a` and `v`. See Also -------- numpy.convolve : Equivalent function in the top-level NumPy module. )rrr<rs rr<r<Es2 ""+q!T> J JJrctt|t|}|turGt|}t|}t j||}|S|rmt|}t|}t j||}t||d}|ddSdS)a Return True if all entries of a and b are equal, using fill_value as a truth value where either or both are masked. Parameters ---------- a, b : array_like Input arrays to compare. fill_value : bool, optional Whether masked values in a or b are considered equal (True) or not (False). Returns ------- y : bool Returns True if the two arrays are equal within the given tolerance, False otherwise. If either array contains NaN, then False is returned. See Also -------- all, any numpy.ma.allclose Examples -------- >>> a = np.ma.array([1e10, 1e-7, 42.0], mask=[0, 0, 1]) >>> a masked_array(data=[10000000000.0, 1e-07, --], mask=[False, False, True], fill_value=1e+20) >>> b = np.array([1e10, 1e-7, -42.0]) >>> b array([ 1.00000000e+10, 1.00000000e-07, -4.20000000e+01]) >>> np.ma.allequal(a, b, fill_value=False) False >>> np.ma.allequal(a, b) True F)ror=TN) rvrYrrXrrKrr rN)rSrrMrrrrrs rrrasT  GAJJ''AF{{ AJJ AJJ K1  uuww  AJJ AJJ K1   115 ) ) )yy""4(((urc t|d}t|d}|jjdkr2tj|d}|j|krt||d}t t |t |}tjt|d|d} tj | ttj|dksdStj | sUttt||z ||t|zz|} tj | Stj t|| || k|sdS|| }|| }ttt||z ||t|zz|} tj | S)aL Returns True if two arrays are element-wise equal within a tolerance. This function is equivalent to `allclose` except that masked values are treated as equal (default) or unequal, depending on the `masked_equal` argument. Parameters ---------- a, b : array_like Input arrays to compare. masked_equal : bool, optional Whether masked values in `a` and `b` are considered equal (True) or not (False). They are considered equal by default. rtol : float, optional Relative tolerance. The relative difference is equal to ``rtol * b``. Default is 1e-5. atol : float, optional Absolute tolerance. The absolute difference is equal to `atol`. Default is 1e-8. Returns ------- y : bool Returns True if the two arrays are equal within the given tolerance, False otherwise. If either array contains NaN, then False is returned. See Also -------- all, any numpy.allclose : the non-masked `allclose`. Notes ----- If the following equation is element-wise True, then `allclose` returns True:: absolute(`a` - `b`) <= (`atol` + `rtol` * absolute(`b`)) Return True if all elements of `a` and `b` are equal subject to given tolerances. Examples -------- >>> a = np.ma.array([1e10, 1e-7, 42.0], mask=[0, 0, 1]) >>> a masked_array(data=[10000000000.0, 1e-07, --], mask=[False, False, True], fill_value=1e+20) >>> b = np.ma.array([1e10, 1e-8, -42.0], mask=[0, 0, 1]) >>> np.ma.allclose(a, b) False >>> a = np.ma.array([1e10, 1e-8, 42.0], mask=[0, 0, 1]) >>> b = np.ma.array([1.00001e10, 1e-9, -42.0], mask=[0, 0, 1]) >>> np.ma.allclose(a, b) True >>> np.ma.allclose(a, b, masked_equal=False) False Masked values are not compared directly. >>> a = np.ma.array([1e10, 1e-8, 42.0], mask=[0, 0, 1]) >>> b = np.ma.array([1.00001e10, 1e-9, 42.0], mask=[0, 0, 1]) >>> np.ma.allclose(a, b) True >>> np.ma.allclose(a, b, masked_equal=False) False Frrr)rr=)r=ro) rxrr(r result_typervrYisinfrNrr!rkr) rSrryrAr@rrrrxinfrs rrrsP QU###AQU###A w|sq"%% 7e  Qe%888A GAJJ''A 8LQ777 8 8 ? ? F FD 6$&!e444 5 5u 6$<< :hq1uootdXa[[6H/HII ! !vayy 6&4AdG+\:: ; ;u 4%A 4%Az(1q5//4$!2D+DEE  A 6!99rc4|pd}t||ddd|S)a Convert the input to a masked array of the given data-type. No copy is performed if the input is already an `ndarray`. If `a` is a subclass of `MaskedArray`, a base class `MaskedArray` is returned. Parameters ---------- a : array_like Input data, in any form that can be converted to a masked array. This includes lists, lists of tuples, tuples, tuples of tuples, tuples of lists, ndarrays and masked arrays. dtype : dtype, optional By default, the data-type is inferred from the input data. order : {'C', 'F'}, optional Whether to use row-major ('C') or column-major ('FORTRAN') memory representation. Default is 'C'. Returns ------- out : MaskedArray Masked array interpretation of `a`. See Also -------- asanyarray : Similar to `asarray`, but conserves subclasses. Examples -------- >>> x = np.arange(10.).reshape(2, 5) >>> x array([[0., 1., 2., 3., 4.], [5., 6., 7., 8., 9.]]) >>> np.ma.asarray(x) masked_array( data=[[0., 1., 2., 3., 4.], [5., 6., 7., 8., 9.]], mask=False, fill_value=1e+20) >>> type(np.ma.asarray(x)) rFT)rr=rrirrx)rSrrs rr0r0 s2X LSE Ud#5 2 2 22rcrt|tr| ||jkr|St||dddS)ae Convert the input to a masked array, conserving subclasses. If `a` is a subclass of `MaskedArray`, its class is conserved. No copy is performed if the input is already an `ndarray`. Parameters ---------- a : array_like Input data, in any form that can be converted to an array. dtype : dtype, optional By default, the data-type is inferred from the input data. order : {'C', 'F'}, optional Whether to use row-major ('C') or column-major ('FORTRAN') memory representation. Default is 'C'. Returns ------- out : MaskedArray MaskedArray interpretation of `a`. See Also -------- asarray : Similar to `asanyarray`, but does not conserve subclass. Examples -------- >>> x = np.arange(10.).reshape(2, 5) >>> x array([[0., 1., 2., 3., 4.], [5., 6., 7., 8., 9.]]) >>> np.ma.asanyarray(x) masked_array( data=[[0., 1., 2., 3., 4.], [5., 6., 7., 8., 9.]], mask=False, fill_value=1e+20) >>> type(np.ma.asanyarray(x)) NFT)rr=rri)r!rrrx)rSrs rr/r/8 sEX![!!u}8H8H Ud$ O O OOrrc td)Nz1fromfile() not yet implemented for a MaskedArray.r)filerrArs rfromfilern s ; = ==rc<t|d|dS)a Build a masked array from a suitable flexible-type array. The input array has to have a data-type with ``_data`` and ``_mask`` fields. This type of array is output by `MaskedArray.toflex`. Parameters ---------- fxarray : ndarray The structured input array, containing ``_data`` and ``_mask`` fields. If present, other fields are discarded. Returns ------- result : MaskedArray The constructed masked array. See Also -------- MaskedArray.toflex : Build a flexible-type array from a masked array. Examples -------- >>> x = np.ma.array(np.arange(9).reshape(3, 3), mask=[0] + [1, 0] * 4) >>> rec = x.toflex() >>> rec array([[(0, False), (1, True), (2, False)], [(3, True), (4, False), (5, True)], [(6, False), (7, True), (8, False)]], dtype=[('_data', '>> x2 = np.ma.fromflex(rec) >>> x2 masked_array( data=[[0, --, 2], [--, 4, --], [6, --, 8]], mask=[[False, True, False], [ True, False, True], [False, True, False]], fill_value=999999) Extra fields can be present in the structured array but are discarded: >>> dt = [('_data', '>> rec2 = np.zeros((2, 2), dtype=dt) >>> rec2 array([[(0, False, 0.), (0, False, 0.)], [(0, False, 0.), (0, False, 0.)]], dtype=[('_data', '>> y = np.ma.fromflex(rec2) >>> y masked_array( data=[[0, 0], [0, 0]], mask=[[False, False], [False, False]], fill_value=999999, dtype=int32) rjrqrr)fxarrays rrVrVs s"z (ww/? @ @ @@rc0eZdZdZdZddZdZdZdZdS) _convert2maz Convert functions from numpy to numpy.ma. Parameters ---------- _methodname : string Name of the method to transform. Nctt||_||||_|pi|_dSr)rr_funcrr_extras)r}rynp_ret np_ma_retrxs rr~z_convert2ma.__init__ s7R** {{6955 | rct|jdd}t|j}|r/||||}|r|jj|d}||z}|S)rrNr")rrr_replace_return_typer)r}rrrrs rrz_convert2ma.getdoc sodj)T22"4:..  ++CCCC <"&*"5"5sss;)C rc ||vr3td|d|d|d|jjd|jjd |||S)a Replace documentation of ``np`` function's return type. Replaces it with the proper type for the ``np.ma`` function. Parameters ---------- doc : str The documentation of the ``np`` method. np_ret : str The return type string of the ``np`` method that we want to replace. (e.g. "out : ndarray") np_ma_ret : str The return type string of the ``np.ma`` method. (e.g. "out : MaskedArray") zFailed to replace `z` with `z-`. The documentation string for return type, z(, is not found in the docstring for `np.z`. Fix the docstring for `np.z0` or update the expected string for return type.)rrrreplace)r}rrrs rrz _convert2ma._replace_return_type s"   >f>>i>>=C>>26*2E>>.2Z-@>>> {{69---rc||j}t||}|D]}||||<|jj|i|t}d|vr|dd|_ d|vr(t|dd|_ |S)NrMrrF) rset intersectionpoprrrlrr*rMrr)r}rrxr common_paramsprUs rrz_convert2ma.__call__ s,F 0099  ' 'AAGAJJ$$d5f55::;GG = ( ( ' L$ ? ?F   & &#GKK U$C$CDDF  rr)rrrrr~rrrrrrrr sfG$$$$   ...8     rrr#)rMrzarange : ndarrayzarange : MaskedArray)rxrrr6zclipped_array : ndarrayzclipped_array : MaskedArrayrIz out : ndarrayzout : MaskedArrayrJ)rrrUzout: MaskedArrayrWzfromfunction : anyzfromfunction: MaskedArrayr_raz'grid : one ndarray or tuple of ndarraysz/grid : one MaskedArray or tuple of MaskedArraysrrrzsqueezed : ndarrayzsqueezed : MaskedArrayrrc&t||g|S)aAppend values to the end of an array. .. versionadded:: 1.9.0 Parameters ---------- a : array_like Values are appended to a copy of this array. b : array_like These values are appended to a copy of `a`. It must be of the correct shape (the same shape as `a`, excluding `axis`). If `axis` is not specified, `b` can be any shape and will be flattened before use. axis : int, optional The axis along which `v` are appended. If `axis` is not given, both `a` and `b` are flattened before use. Returns ------- append : MaskedArray A copy of `a` with `b` appended to `axis`. Note that `append` does not occur in-place: a new array is allocated and filled. If `axis` is None, the result is a flattened array. See Also -------- numpy.append : Equivalent function in the top-level NumPy module. Examples -------- >>> import numpy.ma as ma >>> a = ma.masked_values([1, 2, 3], 2) >>> b = ma.masked_values([[4, 5, 6], [7, 8, 9]], 7) >>> ma.append(a, b) masked_array(data=[1, --, 3, 4, 5, 6, --, 8, 9], mask=[False, True, False, False, False, False, True, False, False], fill_value=999999) )r:)rSrrs rr"r"H!sP 1vt $ $$rr)T)FT)TT)r=r>TTr3r2rr1r0)Nrr)FN)rT)rT)Tr=r>r/(rrvrrCrtextwrapr functoolsrnumpyrnumpy.core.umathr+rnumpy.core.numerictypes numerictypesr numpy.corerrrrrrr r r rnumpy.lib.function_baser numpy.compatr rrrrrnumpy.core.numericr__all__rrr_rrrrrrrr)r, datetime64 timedelta64halfsingledouble longdoublecsinglecdouble clongdoublefloat_types_list_minvalsr:r_maxvalsr7rr$rDr5rrr>rPrrVr7rNrfrXget_datarOrxrrrzrrrrrrrrrLr;rr?r(r'rr@rrrrMrrRr4rr.rprrlrnrmrr&r$r%r*rrrr)rKrrkr\rjr[rorrqrrrr1r2r3r^rHrrSrrTrrrrtrYget_maskrZrfrrsrurrvrPr"rrzr{r~rrryr|rrrr}rKrr]r[dedentr.rfrQr}rrr&rrerhrdr`rwrrxrgrorrrr~rr rr!r8rBrCr=rFr]r`rrrrrrrrrErrrrrrrArrr,r+r-rr9r:rErirrrrrrrrrrGrr5rrrrbrcrrrr>r<rrr0r/rrrVrr#r6rIrJrUrWr_rarrrrrr"rrrrsr,  (((((((((''''''DDDDDDDDDDDDDDDD!!!!!!))))))333333" " " H 8 !     }   8 > > >   "     i           #   ??A&3bmE1&=&=N519s?#&4bnUA&>&>N519s?##GRY 2=J BN< _ >>)9"1")=>>>??? QQ;KBCC;PQQQRRR _ ??*:2A2*>???@@@ QQ;KBCC;PQQQRRR*(((4<4<4 > > B   @6666r60000f Td8 8 8 8 t===  ;;;;;;;;2FFFFFFFF$KKKKKKKK* < < < < < < < < 6 6 6 6 6 6 6 6 --------GGGGGLGGGTPPPPP\PPPhHHHHH|HHHXEI&& ! !%/ 2 2 EI&&EI&&  u| , ,   . .UZ((UZ((UZ((&&u~666he$$UZ((  0 0ek**UZ((  ry ) )##E$566 UZ005577EIs*N3//11UZ+^C0022ek3,nS11 3 3EIs&Ju--//  u|S33D#>> @ @  u|S33D#>> @ @   s 3 3C 8 8 : :   s 4 4\; O O Q QUY'' ! !%. 1 1 ! !%.!Q 7 7 S 9 9u{++ " "5? 3 3   # #E$4 5 5  &&u':;;  ej))  / /$$U%677 !2Aq 9 9 @ # #E$4 5 5  $$U%677 $$U%677 # #E$4 5 5 $$U%677 u{++ " !%,0A0A0C0CQ J J&&u'8'8'8':':AqBB ''(:(9(9(;(;QCC $ $U_%6%6%8%8!Q @ @  ,=,=,?,?AFFuy*;*;*=*=q!DD@ C C C333B8'8'8'v 222jAAAHDVVVVr////d@@@5I5I5I5Ip585858p+-+wwwwt99994????466664<<<<4;;;;4@%1%1%1%1P%1%1%1%1PACACACACHEEEEP!!!!P--------`)(..   $$ X_   X_   ho   ho   +D C C C444n****ZiiiiiiiiXn8n8n8n8n8'n8n8n8bqHHHDDDDDKDDDX0&0&0&f q4q4q4q4q4[q4q4q4h+N,,,  d$$$d! @ @ @ @$ 222tAAAAAAAAFDTBK 6 6 6 6o% DTBK 6 6 6 6o% DTBK6666o% &-&-&-&-&-&-&-&-Rk%;v&&& Dk% ;zD 1 1 1 +i  X  {6 ;z " "k-(( k%  U]G5G H H{6  U]D2D E E +i {6 +f   G X  k-(( k-(( k%k% ;z " " Gk% G::::KKKKZ X   X  Kd$QU < < < <%-& & & & R#&#&#&L9999x////d'''*!'!'!'HEEEE&$ $ $ N#G#G#G#GL&&&&&===@!!!w """  ''''w R[DDDDX 8X)X)X)X)vH H H H V4444j     $OOOOd...);==   # # #);==  )))&LLLL8KKKK87777tiiiiX.2.2.2.2b.P.P.P.Plbb==== =A=A=A@GGGGGGGGT  44% 0 0 0 $     { 44% 0 0 0 $+    44% 0 0 0 !     [ ! [   {  ( ; 44% 0 0 0 !     + 44% 0 0 0 4?     { 44% 0 0 0 !  K !    + 44% 0 0 0 &       44% 0 0 0 !     [ ! (%(%(%(%(%(%r