a :jgOã @sÜUdZddlZddlZddlZddlZddlZddlZddlmZddl m Z ddl Z ddl mmZddlmmZddlmZddl mZmZmZmZmZmZmZddl mZmZm Z m!Z!ddl"m#Z#dd l$m%Z%m&Z&dd l'm(Z(gd ¢Z)e j*Z+e+dƒZ,Gd d „d e-ƒZ.dd„Z/dd„Z0dd„Z1Gdd„de2ƒZ3Gdd„de3ƒZ4dddddddddd œ Z5d!D]6Z6e  7d"e6¡e5d#e6d$<e  8d"e6¡e5d%e6d$<qde j9e j:e j;e je j?gZ@iZAe eBeCfeDd&<iZEe eBeCfeDd'<ejF G¡D]ºZHe  IeH¡ZJeJjKd(vr$e   e jL¡ZMeMjNeMjOZPZQnre  ReJe jS¡rNe   eH¡ZMeMjNeMjOZPZQnHe  ReJe jT¡rxe  !eH¡ZMeMjNeMjOZPZQneJjKd)krŽd*\ZPZQnd+\ZPZQePeAeH<eQeEeH<qîeAZUeU Vd,d-„e@dd.…Dƒ¡eU Vd/d-„e@d0d…Dƒ¡eEZWeW Vd1d-„e@dd.…Dƒ¡eW Vd2d-„e@d0d…Dƒ¡[@d3d4„ZXd5d6„ZYd7d8„ZZd9d:„Z[d;d<„Z\d=d>„Z]d?d@„Z^dAdB„Z_dCdD„Z`dEdF„ZadGdH„ZbdSdIdJ„ZcdKdL„ZddTdMdN„ZeeeZfe,ddfdOdP„ZgdQdR„ZhiZiiZjGdSdT„dTƒZkGdUdV„dVƒZlGdWdX„dXƒZmGdYdZ„dZƒZnGd[d\„d\ƒZoGd]d^„d^ƒZpGd_d`„d`epƒZqGdadb„dbepƒZrGdcdd„ddepƒZseqejtƒZteqejuƒZueqejvƒZveqejwƒZweqejxƒZxeqejyƒZyeqejzƒZzeqej{ƒZ{eqej|ƒZ|eqej}ƒZ~Z}eqeƒZeqejƒZeqej€ƒZ€eqejƒZeqej‚ƒZ‚eqe jƒƒZƒeqej„ƒZ„eqej…deeodeƒƒZ…eqej†dfendeƒƒZ†eqej‡dfendeƒƒZ‡eqejˆdfendeƒƒZˆeqej‰deeldgƒƒZ‰eqejŠdeekdhdfƒƒZŠeqej‹deekdhdfƒƒZ‹eqejŒdfeodfƒƒZŒeqejdeekdidjƒƒZerejŽƒZŽerejƒZerejdkdkƒZerej‘dedfƒZ‘erej’ƒZ’de’_erej“ƒZ“de“_erej”ƒZ”de”_erej•ƒZ•de•_erej–ƒZ–de–_erej—ƒZ—de—_erej˜ƒZ˜erej˜dkdkƒjZ™erejšƒZšešjZ›erejœƒZœerejƒZerejžƒZžerejŸƒZŸerej ƒZ esej¡emƒddkƒZ¡esej¢emƒddkƒZ¢esej£emƒddkƒZ£esej¤emƒddkƒZ¤esej¥emƒddkƒZ¥esej¦emƒddkƒZ¦dldm„Z§dndo„Z¨dpdq„Z©drds„ZªeªZ«dtdu„Z¬dvdw„Z­dxdy„Z®dzde+fd{d|„Z¯dUd}d~„Z°dd€„Z±dVdd‚„Z²dƒd„„Z³e jfd…d†„Z´dWd‡dˆ„ZµdXd‰dŠ„Z¶dYd‹dŒ„Z·dZddŽ„Z¸d[dd„Z¹d\d‘d’„Zºd]d“d”„Z»d^d•d–„Z¼d_d—d˜„Z½d`d™dš„Z¾daddž„Z¿dbdŸd „ZÀGd¡d¢„d¢ƒZÁeÁd£ƒZÂd¤d¥„ZÃeÄe Åd¦¡e Åd§¡e Åd¨¡e Åd©¡dªZÆd«d¬„ZÇd­d®„ZÈdcd¯d°„ZÉGd±d²„d²ƒZÊe(d³ƒGd´dµ„dµeƒƒZËd¶d·„ZÌGd¸d¹„d¹e˃ZÍdºd»„ZÎeÎZÏeÎZÐGd¼d½„d½e˃ZÑeуZÒZÓeËZÔddzde,dddzdddf d¾d¿„ZeÔje_dÀdÁ„ZÕGdÂdÄdÃepƒZÖddde jfdÄdÅ„ZNeËjNjeN_ddde jfdÆdÇ„ZOeËjOjeO_ddde jfdÈdÉ„Z×eËj×je×_GdÊdË„d˃ZØeØd̃ZÙeØd̓ZÚZÛeØd΃ZÜeØdÏddÐZÝeØdуZÞeØdÒƒZßeØdÓƒZàeØdÔƒZáeØdÕƒZâeØdÖƒZãeÖejäe—e]ƒZäeØd׃ZåeÖejæe–e\ƒZæeØd؃ZçeØdÙƒZèeØdÙƒZéeØdÚƒZêeØdÛƒZëeØd܃ZìeØd݃ZíeØdÞƒZîeØd߃ZïeØdàƒZðeØdáƒZñeØdâƒZòeØdãƒZódddådæ„Zôdedçdè„ZõeØdéƒZöeØdêƒZ÷e jddddfddëœdìdí„ZøeËjøjeø_dfddëœdïdð„Zùdñdò„Zúdgdódô„Zûdhdõdö„Züd÷dø„Zýdùdú„Zþdidûdü„Zÿdýdþ„Zdjdÿd„Zdkdd„Zdd„Zdd„Ze jje_dd „Ze jje_dld d „Ze jje_dkdîe je jfd d „Zeefdd„Zdmdd„Z dndd„Z e Z dd„Z dodd„Z dd„Ze0e jjdƒe_eZdd„Ze0e jjdƒe_eZdd„Zdpd d!„Zdqd#d$„Zdrd%d&„Zdsd'd(„Zdtd)d*„Zdud+d,„Zedîd-fd.d/„Zd0d1„ZGd2d3„d3ƒZed4eÄddzd5d6d7d8Zed9eÄddzd5d:d;d8Zedd8Zed?d=d>d@Z edAd=dBd@Z!edCdDdEd@Z"edFeÄddzd5d=d>d8Z#edGeÄddzd5dHdId8Z$edJeÄddzd5d=d>d8Z%edKd=d>d@Z&edLeÄddzd5dMdNd8Z'edOeÄddzd5d=d>d8Z(edPd=d>d@Z)dvdQdR„Z*dS(waú 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)ÚDict)Ú multiarray)ÚndarrayÚamaxÚaminÚ iscomplexobjÚbool_Ú_NoValueÚangle)ÚarrayÚ expand_dimsÚiinfoÚfinfo)Únormalize_axis_tuple)Ú getargspecÚ formatargspec)Ú set_module)²ÚMAErrorÚ MaskErrorÚMaskTypeÚ MaskedArrayÚabsÚabsoluteÚaddÚallÚallcloseÚallequalÚalltruerrr ÚanomÚ anomaliesÚanyÚappendÚarangeÚarccosÚarccoshÚarcsinÚarcsinhÚarctanÚarctan2ÚarctanhÚargmaxÚargminÚargsortÚaroundr Ú asanyarrayÚasarrayÚ bitwise_andÚ bitwise_orÚ bitwise_xorr ÚceilÚchooseÚclipÚcommon_fill_valueÚcompressÚ compressedÚ concatenateÚ conjugateÚconvolveÚcopyÚ correlateÚcosÚcoshÚcountÚcumprodÚcumsumÚdefault_fill_valueÚdiagÚdiagonalÚdiffÚdivideÚemptyÚ empty_likeÚequalÚexpr ÚfabsÚfilledÚ fix_invalidÚ flatten_maskÚflatten_structured_arrayÚfloorÚ floor_divideÚfmodÚ frombufferÚfromflexÚ fromfunctionÚgetdataÚgetmaskÚ getmaskarrayÚgreaterÚ greater_equalÚ harden_maskÚhypotÚidentityÚidsÚindicesÚinnerÚ innerproductÚisMAÚ isMaskedArrayÚis_maskÚ is_maskedÚisarrayÚ left_shiftÚlessÚ less_equalÚlogÚlog10Úlog2Ú logical_andÚ logical_notÚ logical_orÚ logical_xorÚ make_maskÚmake_mask_descrÚmake_mask_noneÚmask_orÚmaskedÚ masked_arrayÚ masked_equalÚmasked_greaterÚmasked_greater_equalÚ masked_insideÚmasked_invalidÚ masked_lessÚmasked_less_equalÚmasked_not_equalÚ masked_objectÚmasked_outsideÚmasked_print_optionÚmasked_singletonÚ masked_valuesÚ masked_whereÚmaxÚmaximumÚmaximum_fill_valueÚmeanÚminÚminimumÚminimum_fill_valueÚmodÚmultiplyÚmvoidÚndimÚnegativeÚnomaskÚnonzeroÚ not_equalÚonesÚ ones_likeÚouterÚ outerproductÚpowerÚprodÚproductÚptpÚputÚputmaskÚravelÚ remainderÚrepeatÚreshapeÚresizeÚ right_shiftÚroundÚround_Úset_fill_valueÚshapeÚsinÚsinhÚsizeÚ soften_maskÚsometrueÚsortÚsqrtÚsqueezeÚstdÚsubtractÚsumÚswapaxesÚtakeÚtanÚtanhÚtraceÚ transposeÚ true_divideÚvarÚwhereÚzerosÚ zeros_likec@s eZdZdS)ÚMaskedArrayFutureWarningN)Ú__name__Ú __module__Ú __qualname__©rÄrÄú7/usr/local/lib/python3.9/site-packages/numpy/ma/core.pyrÀRsrÀcCs&|jdkrdStjdtdddSdS)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. ééÿÿÿÿz«In 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)r‘ÚwarningsÚwarnrÀ)ÚarrrÄrÄrÅÚ_deprecate_argsort_axisUs ürÎcCs\|dur dS|dur|St dt |¡¡}dt |¡}d |dd…|g|dd…¡S)z9 Adds a Notes section to an existing docstring. Nz\n\s*?Notes\n\s*?-----z Notes ----- %s ÚrÆ)ÚreÚsplitÚinspectÚcleandocÚjoin)Z initialdocZnoteZ notesplitZnotedocrÄrÄrÅÚdoc_noteqsrÕcCs,ztt|ƒŽ}Wnty&d}Yn0|S)z% Get the signature from obj rÏ)rrÚ TypeError)ÚobjÚsigrÄrÄrÅÚget_object_signatures   rÙc@seZdZdZdS)rz1 Class for masked array related errors. N©rÁrÂrÃÚ__doc__rÄrÄrÄrÅr’src@seZdZdZdS)rz) Class for mask related errors. NrÚrÄrÄrÄrÅršsrTy@Œµx¯Dg@Œµx¯Di?Bú?sN/As???zN/A) ÚbÚcÚfÚiÚOÚSÚuÚVÚU) ÚYÚMÚWÚDÚhÚmÚsÚmsÚusÚnsZpsÚfsÚasZNaTzM8[ú]zm8[Ú_minvalsÚ_maxvalsÚMmrÝ)rrÆ)NNcCsg|]}|tj f‘qSrÄ©ÚnpÚinf©Ú.0ÚkrÄrÄrÅÚ ÔórüécCs"g|]}|ttj tj ƒf‘qSrÄ©Úcomplexr÷rørùrÄrÄrÅrüÕrýéýÿÿÿcCsg|]}|tj f‘qSrÄrörùrÄrÄrÅrüØrýcCs"g|]}|ttj tj ƒf‘qSrÄrÿrùrÄrÄrÅrüÙrýcshˆjdur6t‡‡fdd„ˆjDƒƒ}tj|ˆddSˆjr\ˆj\}}t|ˆƒ}t ||¡SˆˆƒSdS)zR Recursively produce a fill value for `dtype`, calling f on scalar dtypes Nc3s"|]}t tˆ|ˆƒ¡VqdS©N)r÷r Ú_recursive_fill_value©rúÚname©ÚdtyperßrÄrÅÚ æsÿz(_recursive_fill_value..©rrÄ)ÚnamesÚtupler÷r ÚsubdtyperÚfull)rrßÚvalsÚsubtyper©ZsubvalrÄrrÅrÝs þ   rcCs0t|tjƒr|St|dƒr |jSt |¡jSdS)z4 Convert the argument for *_fill_value into a dtype rN)Ú isinstancer÷rÚhasattrr/©r×rÄrÄrÅÚ _get_dtype_ofòs   rcCsdd„}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) cSs2|jdvr t |jdd…d¡St |jd¡SdS)NrõrÆrÜ)ÚkindÚdefault_fillerÚgetÚstrr rÄrÄrÅÚ_scalar_fill_value)s z.default_fill_value.._scalar_fill_value©rr)r×rrrÄrÄrÅrDüs-rDcs ‡‡fdd„}t|ƒ}t||ƒS)Nc sNz ˆ|jWStyH}z$td|›dˆ›dƒd‚WYd}~n d}~00dS)NzUnsuitable type z for calculating Ú.)ÚtypeÚKeyErrorrÖ)rÚe©ÚextremumÚ extremum_namerÄrÅr5s ÿþz0_extremum_fill_value.._scalar_fill_valuer)r×rr rrrÄrrÅÚ_extremum_fill_value3sr!cCs t|tdƒS)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Œ)r!Ú min_fillerrrÄrÄrÅrAs0rcCs t|tdƒS)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ˆ)r!Ú max_fillerrrÄrÄrÅr‰ts0r‰cCs„t |t|jƒ¡}g}t||jƒD]X\}}||}|jrB|jd}|jdurb| tt||ƒƒ¡q"| tj ||d  ¡¡q"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 ) r÷r¤Úlenr Úzipr r"r Ú_recursive_set_fill_valuer Úitem)Ú fillvalueÚdtZ output_valueÚfvalrZcdtyperÄrÄrÅr&§s  r&c Cs0t |¡}|durt|ƒ}n|jdur¬t|ttjfƒrˆztj||d}Wqªty„}z"d}t|||fƒ|‚WYd}~qªd}~00n"tj|t d}tj t ||ƒ|d}nzt|t ƒrÒ|j dvrÒd}t||ƒ‚nTztj||d}Wn@ttfy$}z"d}t|||fƒ|‚WYd}~n d}~00t  |¡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. Nr z"Unable to transform %s to dtype %sZOSVUz6Cannot set fill value of string with array of dtype %sz(Cannot convert fill_value %s to dtype %s)r÷rrDr rrÚvoidr0Ú ValueErrorÚobjectr r&rÚcharrÖÚ OverflowError)Ú fill_valueÚndtyperÚerr_msgrÄrÄrÅÚ_check_fill_valueÇs.   * ÿ(r3cCst|tƒr| |¡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)rrr¨©Úar0rÄrÄrÅr¨ós<  r¨cCst|tƒr|j}nt|ƒ}|S)zr Return the filling value of a, if any. Otherwise, returns the default filling value for that type. )rrr0rD)r5ÚresultrÄrÄrÅÚget_fill_value4s r7cCs t|ƒ}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)r7)r5rÝÚt1Út2rÄrÄrÅr7As r7cCsFt|dƒr| |¡St|tƒr"|St|tƒr8t |d¡St |¡SdS)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 -------- >>> import numpy.ma as ma >>> x = 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áN)rrNrrÚdictr÷r r4rÄrÄrÅrNas.     rNcGs„t|ƒdkr.|d}t|tƒr(t|ƒ}qrt}nDdd„|Dƒ}|d}t|tƒsRt}|dd…D]}t||ƒr^|}q^|jdkr€tS|S)z Return the youngest subclass of MaskedArray from a list of (masked) arrays. In case of siblings, the first listed takes over. rÆrcSsg|] }t|ƒ‘qSrÄ)r©rúr5rÄrÄrÅrü©rýz'get_masked_subclass..NÚMaskedConstant)r$rrrÚ issubclassrÁ)ÚarraysrÍÚrclsZarrclsÚclsrÄrÄrÅÚget_masked_subclass›s      rAcCs@z |j}Wn"ty,tj|d|d}Yn0|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]]) N©r=Úsubok)Ú_dataÚAttributeErrorr÷r Úviewr)r5rCÚdatarÄrÄrÅrX¶s*   rXcCsXt|||dd}t t |j¡¡}| ¡s.|S|j|O_|durJ|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=ÚmaskrCN)rxr÷rpÚisfiniterDr!Ú_maskr0)r5rHr=r0ÚinvalidrÄrÄrÅrOìs0 rOcCs,t|tƒp*t|tƒo*|o*t dd„|Dƒ¡S)Ncss|]}t|tƒVqdSr)rr)rúrìrÄrÄrÅr)rýz/is_string_or_list_of_strings..)rrÚlistÚbuiltinsr)ÚvalrÄrÄrÅÚis_string_or_list_of_strings&s þrOc@s eZdZdZdd„Zdd„ZdS)Ú_DomainCheckIntervalz~ Define a valid interval, so that : ``domain_check_interval(a,b)(x) == True`` where ``x < a`` or ``x > b``. cCs"||kr||}}||_||_dS)z9domain_check_interval(a,b)(x) = true where x < a or y > bN)r5rÝ©Úselfr5rÝrÄrÄrÅÚ__init__=s z_DomainCheckInterval.__init__cCsPtjdd0t t ||j¡t ||j¡¡WdƒS1sB0YdS)úExecute the call behavior.Úignore©rKN)r÷ÚerrstateÚumathrqr[rÝrjr5©rRÚxrÄrÄrÅÚ__call__Ds ÿz_DomainCheckInterval.__call__N©rÁrÂrÃrÛrSr[rÄrÄrÄrÅrP4srPc@s eZdZdZdd„Zdd„ZdS)Ú _DomainTanz Define a valid interval for the `tan` function, so that: ``domain_tan(eps) = True`` where ``abs(cos(x)) < eps`` cCs ||_dS)z/domain_tan(eps) = true where abs(cos(x)) < eps)N)Úeps)rRr^rÄrÄrÅrSUsz_DomainTan.__init__cCsJtjdd*t t t |¡¡|j¡WdƒS1s<0YdS©úExecutes the call behavior.rUrVN)r÷rWrXrjrr?r^rYrÄrÄrÅr[Ysz_DomainTan.__call__Nr\rÄrÄrÄrÅr]Msr]c@s"eZdZdZddd„Zdd„ZdS)Ú_DomainSafeDividez- Define a domain for safe division. NcCs ||_dSr)Ú tolerance)rRrbrÄrÄrÅrSesz_DomainSafeDivide.__init__cCsx|jdurt t¡j|_t |¡t |¡}}tjdd*t |¡|jt |¡kWdƒS1sj0YdS)NrUrV) rbr÷rÚfloatZtinyr0rWrXrrQrÄrÄrÅr[hs  z_DomainSafeDivide.__call__)Nr\rÄrÄrÄrÅra_s rac@s eZdZdZdd„Zdd„ZdS)Ú_DomainGreaterz4 DomainGreater(v)(x) is True where x <= v. cCs ||_dS)z'DomainGreater(v)(x) = true where x <= vN©Úcritical_value©rRrfrÄrÄrÅrSzsz_DomainGreater.__init__cCs>tjddt ||j¡WdƒS1s00YdSr_)r÷rWrXrkrfrYrÄrÄrÅr[~sz_DomainGreater.__call__Nr\rÄrÄrÄrÅrdtsrdc@s eZdZdZdd„Zdd„ZdS)Ú_DomainGreaterEqualz8 DomainGreaterEqual(v)(x) is True where x < v. cCs ||_dS)z+DomainGreaterEqual(v)(x) = true where x < vNrergrÄrÄrÅrSŠsz_DomainGreaterEqual.__init__cCs>tjddt ||j¡WdƒS1s00YdSr_)r÷rWrXrjrfrYrÄrÄrÅr[Žsz_DomainGreaterEqual.__call__Nr\rÄrÄrÄrÅrh„srhc@seZdZdd„Zdd„ZdS)Ú _MaskedUFunccCs||_|j|_|j|_dSr)rßrÛrÁ)rRÚufuncrÄrÄrÅrS•sz_MaskedUFunc.__init__cCs d|j›S)NzMasked version of )rß©rRrÄrÄrÅÚ__str__šsz_MaskedUFunc.__str__N)rÁrÂrÃrSrlrÄrÄrÄrÅri”srics*eZdZdZd‡fdd„ Zdd„Z‡ZS) Ú_MaskedUnaryOperationaÈ Defines masked version of unary operations, where invalid values are pre-masked. Parameters ---------- mufunc : callable The function for which to define a masked version. Made available as ``_MaskedUnaryOperation.f``. fill : scalar, optional Filling value, default is 0. domain : class instance Domain for the function. Should be one of the ``_Domain*`` classes. Default is None. rNcs,tƒ |¡||_||_|t|<|t|<dSr)ÚsuperrSÚfillÚdomainÚ ufunc_domainÚ ufunc_fills)rRZmufuncrorp©Ú __class__rÄrÅrS°s  z_MaskedUnaryOperation.__init__cOs6t|ƒ}|jdur€tjddd(|j|g|¢Ri|¤Ž}Wdƒn1sN0Yt |¡}|| |¡O}|t|ƒO}nNtjddd(|j|g|¢Ri|¤Ž}Wdƒn1s¼0Yt|ƒ}|jsà|rÜt S|S|t urztj |||dWnt yYn0|  t|ƒ¡}||_| |¡|S)ú- Execute the call behavior. NrU©rHrK©r½)rXrpr÷rWrßrXrIrYr‘rwr“ÚcopytorÖrFrArJÚ _update_from)rRr5ÚargsÚkwargsÚdr6rëÚ masked_resultrÄrÄrÅr[·s. 6 6  z_MaskedUnaryOperation.__call__)rN©rÁrÂrÃrÛrSr[Ú __classcell__rÄrÄrsrÅrmžsrmcsFeZdZdZd‡fdd„ Zdd„Zddd „Zd d „Zdd d „Z‡Z S)Ú_MaskedBinaryOperationaC Define masked version of binary operations, where invalid values are pre-masked. Parameters ---------- mbfunc : function The function for which to define a masked version. Made available as ``_MaskedBinaryOperation.f``. domain : class instance Default domain for the function. Should be one of the ``_Domain*`` classes. Default is None. fillx : scalar, optional Filling value for the first argument, default is 0. filly : scalar, optional Filling value for the second argument, default is 0. rcs0tƒ |¡||_||_dt|<||ft|<dS)zr abfunc(fillx, filly) must be defined. abfunc(x, filly) = x for all x to enable reduce. N)rnrSÚfillxÚfillyrqrr)rRZmbfuncrr‚rsrÄrÅrSüs  z_MaskedBinaryOperation.__init__c Os\t|ƒt|ƒ}}t ¡8tjddd|j||g|¢Ri|¤Ž}Wdƒn1sX0Yt|ƒt|ƒ}} |turœ| turŠt} qÂt t |ƒ| ¡} n&| tur¶t |t |ƒ¡} n t || ¡} |j sÔ| rÐt S|S| tur|   ¡rztj ||d| dWntyYn0| t||ƒ¡} | | _t|tƒrB|  |¡nt|tƒrX|  |¡| S)rurUrvNÚunsafe©Úcastingr½)rXr÷rWZseterrrßrYr“rXrqrZr‘rwr!rxÚ ExceptionrFrArJrrry) rRr5rÝrzr{ÚdaÚdbr6ÚmaÚmbrër}rÄrÄrÅr[ s8 8     z_MaskedBinaryOperation.__call__Nc Cs¬t|ƒ}t|ƒ}t||jƒ}|jdkrJ| d¡}|turJt|dd}d|_|turf|j  ||¡}t}n |jj |||d}t j   ||¡}|js˜|r”t S|S|  |¡} || _| S)z: Reduce `target` along the given `axis`. rÄrÆT©r=©rÆr )rArYrNr‚r©r£r“rsrßrrXrorwrFrJ) rRÚtargetÚaxisrÚtclassrëÚtÚtrÚmrZ masked_trrÄrÄrÅr8s(     z_MaskedBinaryOperation.reducec Cs®t|ƒt|ƒ}}|j ||¡}t|ƒ}t|ƒ}|turF|turFt}nt|ƒ}t|ƒ}tj ||¡}|jsr|rrt S|turŠt j |||d|j s”|S|  t||ƒ¡} || _| S)zO Return the function applied to the outer product of a and b. rw)rXrßr˜rYr“rZrXrqr‘rwr÷rxr©rFrArJ) rRr5rÝr‡rˆr|r‰rŠrëZmasked_drÄrÄrÅr˜Vs$ z_MaskedBinaryOperation.outercCs0t|ƒ}t||jƒ}|j ||¡}| |¡}|S)zSAccumulate `target` along `axis` after filling with y fill value. )rArNr‚rßÚ accumulaterF)rRrrŽrrr6r}rÄrÄrÅr“os   z!_MaskedBinaryOperation.accumulate)rr)rN)r) rÁrÂrÃrÛrSr[rr˜r“rrÄrÄrsrÅr€ès  / r€cs*eZdZdZd‡fdd„ Zdd„Z‡ZS)Ú_DomainedBinaryOperationaH Define binary operations that have a domain, like divide. They have no reduce, outer or accumulate. Parameters ---------- mbfunc : function The function for which to define a masked version. Made available as ``_DomainedBinaryOperation.f``. domain : class instance Default domain for the function. Should be one of the ``_Domain*`` classes. fillx : scalar, optional Filling value for the first argument, default is 0. filly : scalar, optional Filling value for the second argument, default is 0. rcs6tƒ |¡||_||_||_|t|<||ft|<dS)zjabfunc(fillx, filly) must be defined. abfunc(x, filly) = x for all x to enable reduce. N)rnrSrprr‚rqrr)rRZdbfuncrprr‚rsrÄrÅrS‘s  z!_DomainedBinaryOperation.__init__c OsPt|ƒt|ƒ}}tjddd*|j||g|¢Ri|¤Ž}Wdƒn1sP0Yt |¡}|t|ƒO}|t|ƒO}t |jd¡} | dur¢|| ||ƒO}|j s´|r°t S|Sz>tj |dd|dt  ||¡} tj | j|jddrð|| 7}WntyYn0| t||ƒ¡} || _t|tƒr6|  |¡nt|tƒrL|  |¡| S) rTrUrvNrrƒr„Úsafe)r…)rXr÷rWrßrXrIrYrqrr‘rwrxrZcan_castrr†rFrArJrrry) rRr5rÝrzr{r‡rˆr6rërpZ masked_dar}rÄrÄrÅr[œs68         z!_DomainedBinaryOperation.__call__)rrr~rÄrÄrsrÅr”|s r”ççð?gzø·¥•ª8gð¿g÷ÿÿÿÿÿï¿g÷ÿÿÿÿÿï?rÆcCs¬t}|jdurdg}|jD]>}|j|}t|ƒdkr>|d|f}| |||d|ƒf¡qt |¡}n8|jr˜t|jƒ}||jd|ƒ|d<t t |ƒ¡}n|}||kr¨|}|S)z=Private function allowing recursion in _replace_dtype_fields.NrÈrÇr) Ú_replace_dtype_fields_recursiver Úfieldsr$r"r÷rr rLr )rÚprimitive_dtypeZ_recurseÚdescrrÚfieldZ new_dtyperÄrÄrÅr˜s"       r˜cCst |¡}t |¡}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. )r÷rr˜)rršrÄrÄrÅÚ_replace_dtype_fields:s  rcCs t|tƒS)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)r1rÄrÄrÅrtHsrtcCs t|dtƒS)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 rJ)Úgetattrr“)r5rÄrÄrÅrYis8rYcCs,t|ƒ}|tur(tt |¡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)rYr“rur÷r©rž)rÍrHrÄrÄrÅrZ§s/rZcCs(z|jjtuWSty"YdS0dS)a) Return True if m is a valid, standard mask. This function does not check the contents of the input, only that the type is MaskType. In particular, this function returns False if the mask has a flexible dtype. Parameters ---------- m : array_like Array to test. Returns ------- result : bool True if `m.dtype.type` is MaskType, False otherwise. See Also -------- ma.isMaskedArray : Test whether input is an instance of MaskedArray. Examples -------- >>> 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 FN)rrrrE©rërÄrÄrÅrfÜs> rfcCs |jjdur| ¡stS|SdS)z- Shrink a mask to nomask if possible N)rr r!r“rŸrÄrÄrÅÚ _shrink_mask sr FcCst|tur tSt|ƒ}t|tƒr@|jjr@|tjkr@tj|j |dS|sHdnd}tj t |dƒ||dd}|rpt |ƒ}|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')]) r NT)r=rrC) r“rtrrrr™r÷Úboolr–r©r rNr )rër=Úshrinkrr6rÄrÄrÅrs*sG rscCs.|durtj|td}ntj|t|ƒd}|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 )r÷r¾rrt)Únewshaperr6rÄrÄrÅru„s+rucCsV|jj}|D]D}||}|jjdur:t|||||ƒq t |||||¡q dSr)rr Ú_recursive_mask_orrXrq)Úm1Úm2Únewmaskr rZcurrent1rÄrÄrÅr¤¶s  r¤cCsä|tus|dur,t|dtƒ}t||||dS|tus<|durXt|dtƒ}t||||dS||urlt|ƒrl|St|ddƒt|ddƒ}}||kržtd||fƒ‚|jdurÎt t  ||¡j |¡}t |||ƒ|Stt   ||¡||dS)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=r¢rNzIncompatible dtypes '%s'<>'%s'©r=r¢)r“ržrrsrfr,r r÷rIÚ broadcastr©r¤rXrq)r¥r¦r=r¢rZdtype1Zdtype2r§rÄrÄrÅrvÀs %    rvcsBdd„}‡fdd„‰t |¡}ˆ||ƒƒ}tjdd„|DƒtdS)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]) cs*ˆjj}|dur"‡fdd„|DƒSˆSdS)zCFlatten the mask and returns a (maybe nested) sequence of booleans.Ncsg|]}tˆ|ƒ‘qSrÄ)rPr©rHrÄrÅrürýz3flatten_mask.._flatmask..©rr )rHZmnamesrÄrªrÅÚ _flatmaskszflatten_mask.._flatmaskc3sLz.|D]$}t|dƒr$ˆ|ƒEdHq|VqWntyF|VYn0dS)z.Generates a flattened version of the sequence.Ú__iter__N)rrÖ)ÚsequenceÚelement©Ú _flatsequencerÄrÅr± s   z#flatten_mask.._flatsequencecSsg|]}|‘qSrÄrÄ©rúÚ_rÄrÄrÅrü-rýz flatten_mask..r )r÷r0r r¡)rHr¬Z flattenedrÄr°rÅrPøs   rPcCs6|tjurind|i}|tur2|jfd|i|¤ŽStS)z:Check whether there are masked values along the given axisÚkeepdimsrŽ)r÷r r“r)rHrŽr´r{rÄrÄrÅÚ_check_mask_axis0srµcCs¨t|dd}tj||dd}|j|j}}|rF||krFtd||fƒ‚t|dƒrft||jƒ}t|ƒ}nt }|  |¡}t |ƒ|_ |s¤t|dƒr¤t |ƒ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) F©r¢TrBzFInconsistent shape between the condition and the input (got %s and %s)rJ)rsr÷r r©Ú IndexErrorrrvrJrrrFr rHrYr“)Ú conditionr5r=ZcondZcshapeZashaper@r6rÄrÄrÅr†<s d  ÿ      r†cCstt||ƒ||dS)aì Mask an array where greater 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_greater(a, 2) masked_array(data=[0, 1, 2, --], mask=[False, False, False, True], fill_value=999999) r‹)r†r[©rZÚvaluer=rÄrÄrÅrz¶srzcCstt||ƒ||dS)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‹)r†r\r¹rÄrÄrÅr{Ðsr{cCstt||ƒ||dS)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‹)r†rjr¹rÄrÄrÅr~êsr~cCstt||ƒ||dS)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‹)r†rkr¹rÄrÄrÅrsrcCstt||ƒ||dS)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‹)r†r•r¹rÄrÄrÅr€sr€cCstt||ƒ||d}||_|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‹)r†rKr0)rZrºr=ÚoutputrÄrÄrÅry8srycCs8||kr||}}t|ƒ}||k||k@}t|||dS)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) r‹©rNr†©rZZv1Zv2r=Zxfr¸rÄrÄrÅr|Xs ! r|cCs8||kr||}}t|ƒ}||k||kB}t|||dS)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) r‹r¼r½rÄrÄrÅr‚€s ! r‚cCsVt|ƒrt |j|¡}|j}nt t |¡|¡}t}t|t ||dƒ}t ||||dS)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¶©rHr=r0) rerXrKrDrJr÷r0r“rvrsrx)rZrºr=r¢r¸rHrÄrÄrÅr¨s:rçñh㈵øä>ç:Œ0âŽyE>c CsZt||ƒ}t |jtj¡r.tj||||d}n t ||¡}t||||d}|rV|  ¡|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) )ÚatolÚrtolr¾) rNr÷Ú issubdtyperÚfloatingÚiscloserXrKrxÚ shrink_mask) rZrºrÂrÁr=r¢ZxnewrHÚretrÄrÄrÅr…ìs=  r…cCsDtj|ddd}tt |¡||d}|jtur@t|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.inf >>> 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) NTrBr‹) r÷r r†rIrJr“rur©r)r5r=ÚresrÄrÄrÅr}4 s  r}c@sFeZdZdZdd„Zdd„Zdd„Zdd „Zdd d „Zd d„Z e Z dS)Ú_MaskedPrintOptionzN Handle the string used to represent missing data in a masked array. cCs||_d|_dS)z9 Create the masked_print_option object. TN)Ú_displayÚ_enabled)rRÚdisplayrÄrÄrÅrSb sz_MaskedPrintOption.__init__cCs|jS)zA Display the string to print for masked values. ©rÊrkrÄrÄrÅrÌj sz_MaskedPrintOption.displaycCs ||_dS)z= Set the string to print for masked values. NrÍ)rRrìrÄrÄrÅÚ set_displayq sz_MaskedPrintOption.set_displaycCs|jS)z; Is the use of the display value enabled? ©rËrkrÄrÄrÅÚenabledx sz_MaskedPrintOption.enabledrÆcCs ||_dS)z7 Set the enabling shrink to `shrink`. NrÏ)rRr¢rÄrÄrÅÚenable sz_MaskedPrintOption.enablecCs t|jƒSr)rrÊrkrÄrÄrÅrl† sz_MaskedPrintOption.__str__N)rÆ) rÁrÂrÃrÛrSrÌrÎrÐrÑrlÚ__repr__rÄrÄrÄrÅrÉ\ s rÉz--cCsL|jj}|dur8|D] }||}||}t|||ƒqntj|||ddS)zg Puts printoptions in result where mask is True. Private function allowing for recursion Nrw)rr Ú_recursive_printoptionr÷rx)r6rHZprintoptr rZcurdataZcurmaskrÄrÄrÅrÓ srÓ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) 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) )Zlong_stdZlong_flxZ short_stdZ short_flxcCsX|jj}|D]F}||}|jjdur:t|||||ƒq tj|||||dq dS)z2 Recursively fill `a` with `fill_value`. Nrw)rr Ú_recursive_filledr÷rx)r5rHr0r rÚcurrentrÄrÄrÅrÔà s  rÔcsº‡fdd„‰t |¡}|j}| ¡}t|tƒrrt ‡fdd„|jDƒ¡}| t¡}t ‡fdd„t |ƒDƒ¡|_ nt ‡fdd„|Dƒ¡}t |ƒdkr¶t |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.]]) c3s2t|ƒD]$}t|dƒr&ˆ|ƒEdHq|VqdS)z; Flattens a compound of nested iterables. r­N)Úiterr)ÚiterableÚelm©Úflatten_sequencerÄrÅrÚì s  z2flatten_structured_array..flatten_sequencecsg|]}tˆ| ¡ƒƒ‘qSrÄ©r r'©rúr|rÙrÄrÅrüû rýz,flatten_structured_array..csg|]}tˆ| ¡ƒƒ‘qSrÄrÛrÜrÙrÄrÅrüý sÿcsg|]}tˆ| ¡ƒƒ‘qSrÄrÛrÜrÙrÄrÅrü rýrÆr)r÷r/r©r rrr rDrFrZrJr$rLr )r5ÚinishapeÚoutr£rÄrÙrÅrQÑ s    ÿ   rQcs@‡‡fdd„}ttˆdƒp$ttˆdƒ}|dur6|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. csft|jˆƒ|i|¤Ž}| t|ƒ¡}| |¡|j}ˆsD| |¡n|turbt|ˆƒ|i|¤Ž|_|Sr)ržrDrFrryrJÚ __setmask__r“)rRrzÚparamsr6rH©ÚfuncnameÚonmaskrÄrÅÚwrapped_method# s  z$_arraymethod..wrapped_methodN)ržrr÷rÛrÁ)rârãräZmethdocrÄrárÅÚ _arraymethod s  råc@s8eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd S) Ú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) cCs0||_|jj|_|jtur"d|_n |jj|_dSr)r‰rDÚflatÚdataiterrJr“Úmaskiter)rRr‰rÄrÄrÅrSe s   zMaskedIterator.__init__cCs|SrrÄrkrÄrÄrÅr­n szMaskedIterator.__iter__cCsr|j |¡ t|jƒ¡}|jdurn|j |¡}t|tƒrH|j|_||_ n&t|t j ƒrft |||jj dS|rntS|S)N©rHÚhardmask)rèÚ __getitem__rFrr‰rérrr©rJr÷r+rÚ _hardmaskrw)rRÚindxr6rJrÄrÄrÅrìq s    zMaskedIterator.__getitem__cCs*t|ƒ|j|<|jdur&t|ƒ|j|<dSr)rXrèrérZ)rRÚindexrºrÄrÄrÅÚ __setitem__€ s zMaskedIterator.__setitem__cCsHt|jƒ}|jdurDt|jƒ}t|tjƒr>> 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ê) Únextrèrérr÷r+rr‰rírw)rRr|rërÄrÄrÅÚ__next__… s    zMaskedIterator.__next__N) rÁrÂrÃrÛrSr­rìrðròrÄrÄrÄrÅræ5 s / ræznumpy.mac s eZdZdZdZeZdZeZ dZ dZ dedddddddddf d d „Z d d „Z d d„Zdídd„Zdîdd„Zdd„Zejddddd„ƒZe‡fdd„ƒZej‡fdd„ƒZe‡fdd„ƒZej‡fdd„ƒZdïdd „ZeZed!d"„ƒZejd#d"„ƒZed$d%„ƒZejd&d%„ƒZd'd(„Zd)d*„Zed+d,„ƒZd-d.„Z ed/d0„ƒZ!d1d2„Z"ed3d4„ƒZ#d5d6„Z$ee$d7Z%ee$d7Z&ed8d9„ƒZ'e'jd:d9„ƒZ'ed;d<„ƒZ(e(jdðd=d<„ƒZ(e(j)Z*e(j+Z,dñd>d?„Z-d@dA„Z.dòdBdC„Z/dDdE„Z0dFdG„Z1dHdI„Z2dJdK„Z3dLdM„Z4dNdO„Z5dPdQ„Z6dRdS„Z7dTdU„Z8dVdW„Z9dXdY„Z:dZd[„Z;d\d]„Zdbdc„Z?ddde„Z@dfdg„ZAdhdi„ZBdjdk„ZCdldm„ZDdndo„ZEdpdq„ZFdrds„ZGdtdu„ZHdvdw„ZIdxdy„ZJdzd{„ZKd|d}„ZLd~d„ZMd€d„ZNd‚dƒ„ZOd„d…„ZPed†d‡„ƒZQeQj)ZRedˆd‰„ƒZSeSj)ZTdejUfdŠd‹„ZVdóddŽ„ZWdd„ZXdôd‘d’„ZYdõd”d•„ZZd–d—„Z[d˜d™„Z\ddejUfdšd›„Z]ddejUfdœd„Z^dždŸ„Z_dö‡fd¡d¢„ Z`ej`je`_d÷d£d¤„ZadddejUfd¥d¦„Zbdød§d¨„ZcdddejUfd©dª„ZdedZedùd«d¬„ZfdddejUf‡fd­d®„ Zgdúd¯d°„ZhddddejUejUf‡fd±d²„ Ziejijei_ddddejUejUfd³d´„Zjdûdµd¶„ZkejUddddfdd·œd¸d¹„ZldüejUdºœd»d¼„ZmdýejUdºœd½d¾„Zndþdd·œdÀdÁ„ZodddejUfdÂdÄZpdddejUfdÄdÅ„ZqdÿdÆdÇ„Zr‡fdÈdÉ„Zs‡fdÊdË„ZtddÌdÍ„Zuevd΃ZwevdσZxevdЃZyevdуZzevdÒƒZ{evdÓƒZ|edÔdÕ„d7Z}evdÖƒZ~ed×dØ„ƒZddÙdÚ„Z€ddÛdÜ„ZddÝdÞ„Z‚ddádâ„Zƒdãdä„Z„e„Z…‡fdådæ„Z†‡fdçdè„Z‡dédê„Zˆddëdì„Z‰‡ZŠS(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 éFédiÜNTrc  s\|sdnd}tj|||| d|d‰t|dtˆƒƒ} t|tƒrL|jˆjkrLd}t||ƒrv|rvt|tƒsvt  ˆt|ƒ¡‰n t  ˆ|¡‰t |dƒržt|tƒsž|j ˆ_ t ˆj ƒ‰|turŒ|sÖ| rÂtˆ_ ntjˆjˆdˆ_ n²t|ttfƒrFz tj‡fdd„|Dƒˆd}Wnttfy"t}Yn0ˆtkrˆ| ¡rˆ|ˆ_ d ˆ_nB| ˆ_|rˆj  ¡ˆ_ t|ƒtur|j j|jkr|j|j _nx|duršd }|durÀˆtkrÀtjˆjˆd}nl|d uræˆtkrætjˆjˆd}nFztj||ˆd }Wn0ty*tj‡fd d„|Dƒˆd}Yn0|jˆjkr”ˆj|j} }|d krbt |ˆj¡}n.|| kr|t |ˆj¡}nd }t|| |fƒ‚d}ˆj tur°|ˆ_ | ˆ_nT|sÆ|ˆ_ | ˆ_n>ˆj jdurî‡fdd„‰ˆˆj |ƒnt |ˆj ¡ˆ_ d ˆ_|durt|ddƒ}|dur2t |ˆj ƒˆ_!| durLt|dd ƒˆ_"n| ˆ_"| ˆ_#ˆS)z¢ Create a new masked array from scratch. Notes ----- A masked array can also be created by taking a .view(MaskedArray). NT)rr=ÚorderrCÚndminÚ _baseclassrJr cs g|]}ttj|ˆjdƒ‘qS)r )rZr÷r/r©rúrë)rDrÄrÅrüD sÿz'MaskedArray.__new__..F©r=rcsg|]}t|gtˆƒƒ‘qSrÄ©r r$rø©ÚmdtyperÄrÅrüm rýrÆz?Mask and data not compatible: data size is %i, mask size is %i.csD|jjD]6}||||}}|jjdur6ˆ||ƒq||O}qdS)z'do a|=b on each field of a, recursivelyNr«)r5rÝrÚafÚbf)Ú _recursive_orrÄrÅrÿ… s    z*MaskedArray.__new__.._recursive_orÚ _fill_valuerí)$r÷r ržrrrr©r<rrFrrJrtrr“r¾r rLr,rÖrr!Ú _sharedmaskr=rYr–r¬r¤r£rr rqr3rrír÷)r@rGrHrr=rCrör0Ú keep_maskÚ hard_maskr¢rõr÷ÚndÚnmÚmsgrÄ)rDrÿrürÅÚ__new__ sœ  ÿ    ÿþ    ÿ           zMaskedArray.__new__c Cs¶t|tƒrt|ƒ}nt}i}| t|diƒ¡| t|diƒ¡t|tƒs\| t|diƒ¡tt|ddƒt|ddƒt|ddƒt|d dƒt|d |ƒ||d }|j |¡|j |¡dS) z9 Copies some attributes of obj to self. Ú_optinfoÚ _basedictÚ__dict__rNríFrÚ_isfieldr÷)rrírr r÷rr )rrrÚupdateržrr:r )rRr×r÷rÚ_dictrÄrÄrÅry¢ s&        ú  zMaskedArray._update_fromc Cs:| |¡t|tƒr¬|jjdur*t|ƒ}nt|ƒ}|tur¢|jdd|jddkr¢|j|jkrj|j}n t |jƒ}|j j r‚d}n|j j rd}nd}|  ||¡}q°| ¡}nt}||_|jturüz|j|j_Wn,tyæt|_YnttfyúYn0|jdurt|j|jƒ|_n|jjdur6td|jƒ|_dS)z. Finalizes the masked array. NrGrÚCÚFÚK)ryrrrr rZrYr“Z__array_interface__rtÚflagsÚ c_contiguousÚ f_contiguousÚastyperFrJr©r,rÖrErr3)rRr×rJZ _mask_dtyperõrÄrÄrÅÚ__array_finalize__¼ s>      ÿ       zMaskedArray.__array_finalize__c Cs`||ur|}n| t|ƒ¡}| |¡|dur\|j ¡|_|\}}}|d|j…}ttdd„|Dƒƒ} t  |d¡} | dur0t j dddt | |Ždƒ} Wdƒn1s°0Y|   ¡r0zt|d} Wn2tyît|} Ynty|j} Yn0t j|| | d| tur(| } n| | B} ||urP|jd krP| rPtS| |_d |_|S) zr Special hook for ufuncs. Wraps the numpy array and sets the mask according to context. NcSsg|] }t|ƒ‘qSrÄ©rZ)rúÚargrÄrÄrÅrü+ rýz.MaskedArray.__array_wrap__..rUrvTrÇrwrÄF)rFrryrJr=Zninrrvrqrr÷rWrNr!rrrÖrr0rxr“r©rwr) rRr×ÚcontextÚ return_scalarr6ÚfuncrzZout_iZ input_argsrërpr|r0rÄrÄrÅÚ__array_wrap__ s:      ,     zMaskedArray.__array_wrap__cCsÚ|dur*|durt |¡}qŽt ||¡}nd|dur€z,t|tƒrPt ||¡}d}n t ||¡}WqŽty|t ||¡}YqŽ0nt |||¡}t|ƒtur¦|j ¡|_t|ddƒdurÖ|durÐ|durÈqÖd|_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) rrFr=rÖrYr“rJržrr0)rRrrr0r»rÄrÄrÅrFQ s,8      zMaskedArray.viewcCs¤|j|}|j}dd„}dd„}|tur:||}||ƒ}n(t}||j|ƒ}|durb|t|ƒ|ƒ}|rÈt|tjƒr‚t|||jdS|j j tj urºt|tj ƒrº|t urº|r´t|ddS|Sn |rÂt S|SnØ| t |ƒ¡}| |¡t|ƒr‚|jdur||j||_t|jtj ƒstd ƒ‚|jjd kr||j|jjd k ¡sbtjd |›d |jd ›d dd|jjd d…jd d|_d|_|tur t||jƒ|_d|_|S)zi x.__getitem__(y) <==> x[y] Return the item described by i, as a masked array. cSst|tjƒ Sr)rr÷rrŸrÄrÄrÅÚ _is_scalar¹ sz+MaskedArray.__getitem__.._is_scalarcSsHt|tjƒsdS|jjtjur0|j|jurDdSnt|ƒjtjkrDdSdS)z  Return whether `elem` is a scalar result of indexing `arr`, or None if undecidable without promoting nomask to a full mask TFN)rr÷rrrÚobject_rì)rÍÚelemrÄrÄrÅÚ_scalar_heuristic¼ s  z2MaskedArray.__getitem__.._scalar_heuristicNrêTrªzInternal 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 rérÉrÆ©rŽ)rGrJr“rZrr÷r+rrírrrrrwrrFryrOrÚ RuntimeErrorr‘rçrrËrÌr±r r£r©r)rRrîZdoutrJrrZmoutZscalar_expectedrÄrÄrÅrì« sd     ÿþ       ÿ ÿüú  zMaskedArray.__getitem__rU)ZoverrKc Cs|turtdƒ‚|j}|j}t|tƒrZ|||<|turJt|j|j ƒ|_}t |ƒ||<dS|j }|tur²|tur‚t|j|ƒ}|_|j dur¦t dgt |j ƒƒ||<nd||<dSt|d|ƒ}t |ƒ}|j durì|turìt dgt |j ƒƒ}|tur$|||<|turt|j|ƒ}|_|||<nà|jsbt|tƒrPt|tƒsP|||j<n|||<|||<n¢t|dƒr’|j tkr’|t |¡}|||<nr|j durªd}t|ƒ‚t|||dd} |j|} | jd krætj| || d n| turô|} | ||<| ||<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.NTrDFrz,Flexible 'hard' masks are not yet supported.r‹rÆrw)rwrrDrJrrr“rur©rrYr r r$ržrírxrGrrrXrpÚNotImplementedErrorrvr¬r÷rx) rRrîrºrDrJZ_dtypeÚdvalZmvalr2ZmindxZdindxrÄrÄrÅrð, sb         ÿ       zMaskedArray.__setitem__cstƒjSr)rnrrkrsrÄrÅrs szMaskedArray.dtypec s`ttt|ƒƒj ||¡|jtur\|j t|ƒt ¡|_z|j |j_ Wnt t fyZYn0dSr) rnrrrÚ__set__rJr“rFrtrr©rErÖ)rRrrsrÄrÅrw s cstƒjSr)rnr©rkrsrÄrÅr©ƒ szMaskedArray.shapecs2ttt|ƒƒj ||¡t|ƒtur.|j|j_dSr)rnrrr©r%rYr“rJ)rRr©rsrÄrÅr©‡ s csŠ|j}|j}|turd}|tur>|tur,dSt|j|ƒ}|_|jdur€|jrX||O}n&t|t t t j t j fƒrx||d<n||_nö|j‰t  |¡}|jsÐ|jjdkrÄt jt| ¡gtˆƒƒˆd}n | ˆ¡}nRz |sÚdnd}t j||ˆd}Wn0ty t j‡fdd„|Dƒˆd}Yn0|jrN|jD]}||||O<q0n(t|t t t j t j fƒrp||d<n||_|jr†|j|_dS) z Set the mask. TN.rÝr rùcsg|]}t|gtˆƒƒ‘qSrÄrúrørûrÄrÅrü rýz+MaskedArray.__setmask__..)rrJrwr“rur©r rírÚintrcr÷r¡Únumberrçr0r‘rr r r'r$rrÖ)rRrHr=ZidtypeZ current_maskÚnrÄrûrÅrß sL     ÿ  ÿ   zMaskedArray.__setmask__cCs |j ¡S)z Current mask. )rJrFrkrÄrÄrÅrH× szMaskedArray.maskcCs| |¡dSr)rß)rRrºrÄrÄrÅrHá scCs.|j t¡}|jjdur|Stjt|ƒddS)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]) NrÇr!)rJrFrrr r÷rrQ)rRrJrÄrÄrÅÚ recordmaskå s  zMaskedArray.recordmaskcCs tdƒ‚dS)Nz*Coming soon: setting the mask per records!©r#)rRrHrÄrÄrÅr)ø scCs d|_|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 T©rírkrÄrÄrÅr]ü szMaskedArray.harden_maskcCs d|_|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 Fr+rkrÄrÄrÅr­szMaskedArray.soften_maskcCs|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) r+rkrÄrÄrÅrë s*zMaskedArray.hardmaskcCs|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)rrJr=rkrÄrÄrÅÚ unshare_maskLs  zMaskedArray.unshare_maskcCs|jS)z' Share status of the mask (read-only). )rrkrÄrÄrÅÚ sharedmask^szMaskedArray.sharedmaskcCst|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 )r rJrkrÄrÄrÅrÆcs zMaskedArray.shrink_maskcCs|jS)z+ Class of the underlying data (read-only). )r÷rkrÄrÄrÅÚ baseclass‚szMaskedArray.baseclasscCst ||j¡S)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. )rrFr÷rkrÄrÄrÅÚ _get_data‡szMaskedArray._get_data)ÚfgetcCst|ƒS)zF Return a flat iterator, or set a flattened version of self to value. )rærkrÄrÄrÅrç›szMaskedArray.flatcCs| ¡}||dd…<dSr)r )rRrºÚyrÄrÄrÅrç scCs4|jdurtd|jƒ|_t|jtƒr.|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() ... np.int64(999999) np.int64(999999) np.float64(1e+20) np.complex128(1e+20+0j) >>> x = np.ma.array([0, 1.], fill_value=-np.inf) >>> x.fill_value np.float64(-inf) >>> x.fill_value = np.pi >>> x.fill_value np.float64(3.1415926535897931) Reset to default: >>> x.fill_value = None >>> x.fill_value np.float64(1e+20) NrÄ)rr3rrrrkrÄrÄrÅr0¥s    zMaskedArray.fill_valuecCsHt||jƒ}|jdks&tjdtdd|j}|dur<||_n||d<dS)Nrz™Non-scalar arrays for the fill value are deprecated. Use arrays with scalar values instead. The filled function still supports any array as `fill_value`.r rÉrÄ)r3rr‘rËrÌÚDeprecationWarningr)rRrºrrrÄrÄrÅr0Îs  üc Cs|j}|tur|jS|dur$|j}n t||jƒ}|turBt |¡S|jj durj|j  d¡}t ||j|ƒn¨|  ¡sx|jS|j  d¡}ztj |||dWnxttfyÔt|td}| t¡}t |||f¡}Yn>ty|jjrî‚n|rtj||jd}n|j}Yn0|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', '>> x = np.ma.array(np.arange(5), mask=[0]*2 + [1]*3) >>> x.compressed() array([0, 1]) >>> type(x.compressed()) N-D arrays are compressed to 1-D. >>> arr = [[1, 2], [3, 4]] >>> mask = [[1, 0], [0, 1]] >>> x = np.ma.array(arr, mask=mask) >>> x.compressed() array([2, 3]) )rr rDrJr“r8r÷rp)rRrGrÄrÄrÅr95s  zMaskedArray.compressedcCsX|j|j}}t |¡}|j|||d t|ƒ¡}| |¡|turT|j||d|_|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) ©rŽrÞr!) rDrJr÷r0r8rFrryr“)rRr¸rŽrÞrDrJÚ_newrÄrÄrÅr8Xs<  zMaskedArray.compressc Csôt ¡rä|j}|tur|j}qð|j}|jdkr4|jn|j}t|jƒD]z}|j ||krD|d}t j ||| f|d}t j |d|df|d}t j ||| f|d}t j |d|df|d}qDt |jdƒ}| |¡}t||tƒn | |j¡}|S)zq Replace masked values with masked_print_option, casting all innermost dtypes to object. rÆr r!rrá)rƒrÐrJr“rDr‘Ú _print_widthÚ_print_width_1dÚranger©r÷rÑr:rrrrÓrNr0) rRrHrÈrGZ print_widthrŽÚindrÍÚrdtyperÄrÄrÅÚ_insert_masked_print s(ÿ   z MaskedArray._insert_masked_printcCs t| ¡ƒSr)rr;rkrÄrÄrÅrl¿szMaskedArray.__str__cs‚|jtjurd}n|jj}tjj ¡dkrš|jdk}t|dt |ƒt |ƒt |j ƒt |j ƒt |j ƒd}t|j jƒ}d |r~dnd|rˆd nd ¡}t||Sd |›d }tjj |j ¡ pÌt |j¡pÌ|jd k}gd¢}|rä| d¡t dd„|jdd…Dƒ¡} d‰| rbi‰|ˆ|d <|dd…D]2} t ˆt ||d ƒt | ƒ¡} d| ˆ| <q(d}n‡fdd„|Dƒ‰|d}i‰tj| ¡dˆddddˆd<tj|j dˆddddˆd<|jdurÔ|j |jj jd vr|j j|jj jkrt|j  ¡ƒ} n2|jj |j kr0|j t ks0t |j ƒ} n t|j ƒ} | ˆd!<|r\tjj !|j ¡ˆd<d" "‡‡fd#d„|Dƒ¡} || d$S)%z1 Literal string representation. r éqrÆú )rÚnlenrGrHrorz{}_{}ÚlongÚshortÚflxr²Zmasked_ú(r)rGrHr0rcss|]}|dkVqdS)rÆNrÄ)rúÚdimrÄrÄrÅrírýz'MaskedArray.__repr__..NrÇr rÏcsi|]}|dˆ“qS)r=rÄrù)Ú min_indentrÄrÅÚ ürýz(MaskedArray.__repr__..Ú z, rGzdata=ú,)Ú separatorÚprefixÚsuffixrHzmask=)rârår0z, c3s$|]}d ˆ||ˆ|¡VqdS)z{}{}={}N)Úformatrù)ÚindentsÚreprsrÄrÅrsÿú))#r÷r÷rrÁÚ_coreZ arrayprintZ_get_legacy_print_moder‘r:r$rrJr0rr¡r rKÚ_legacy_print_templatesZdtype_is_impliedrrHr¬r"rMr©r‡Z array2stringr;rrÚreprr'r-Zdtype_short_reprrÔ)rRrZis_longÚ parametersZ is_structuredÚkeyrIZ dtype_neededÚkeysZ is_one_rowrûr(Z fill_reprr6rÄ)rLrDrMrÅrÒÂsˆ   ú   þ   ÿý    ü  ü  ÿ  þzMaskedArray.__repr__cCsHt|t|ƒƒrdSt|ddƒ}|dur>> 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) )rDÚimagrFrrßrJ©rRr6rÄrÄrÅrŒ©s zMaskedArray.imagcCs"|jj t|ƒ¡}| |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) )rDÚrealrFrrßrJrrÄrÄrÅrŽÄs zMaskedArray.realc s\|tjurind|i}|j}t|jtjƒrT|turDtj|jtj d}|  t |jƒ¡}|tur4|jdkr†|dvr‚tj j ||jd‚dS|dur¶| dd¡r°tj|jtj|jd S|jSt||jƒ‰d}ˆD]}||j|9}qÊ| dd¡r t|jƒ}ˆD] }d||<qún‡fd d „t|jƒDƒ}tj||tjdS|turBd S|jf|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´r rÄ©Nr)rŽr‘rÆNF)rröcsg|]\}}|ˆvr|‘qSrÄrÄ)rúr(r|©ÚaxesrÄrÅrü7s ÿz%MaskedArray.count..r©rŽr)r÷r rJrrGÚmatrixr“r¾r©r¡rFrÚ exceptionsZ AxisErrorr‘rr r¬ZintprrLÚ enumerater rwr´) rRrŽr´r{rëÚitemsÚaxZout_dimsr5rÄrrÅrAßs88       zMaskedArray.countrcCsn|dvr|jjjrdnd}tj|j|d t|ƒ¡}| |¡|jt urdtj|j|d  |j ¡|_nt |_|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) ZkKaArr©rõ) rDrÚfncrr rFrryrJr“r£r©)rRrõÚrrÄrÄrÅr Bs3  zMaskedArray.ravelcOs^|j| dd¡d|jj|i|¤Ž t|ƒ¡}| |¡|j}|turZ|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) rõrr˜) r rrDr£rFrryrJr“)rRrìr{r6rHrÄrÄrÅr£€s: zMaskedArray.reshapecCsd}t|ƒ‚dS)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.N)r,)rRr£ZrefcheckrõÚerrmsgrÄrÄrÅr¤Âs zMaskedArray.resizeÚraisecCsÐ|jrT|jturT|j|}t|dd}t|ddd}| |j¡||}||}|jj|||d|jtur€t|ƒtur€dSt |ƒ}t|ƒtur¦|j|d|dn|j||j|dt |ddd}||_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) Nr‹TrB©ÚmodeFr¨) rírJr“r3r¤r©rDržrYrZrs)rRraÚvaluesržrHrërÄrÄrÅržÔs"=      zMaskedArray.putcCs,|jtur|jjttƒfS|jj|jjjfS)a Return the addresses of the data and mask areas. Parameters ---------- None Examples -------- >>> 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 )rJr“ÚctypesrGÚidrkrÄrÄrÅr`)s zMaskedArray.idscCs |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 Z CONTIGUOUS)rrkrÄrÄrÅÚ iscontiguousCszMaskedArray.iscontiguouscCs²|tjurind|i}t|j|fi|¤Ž}|durt| d¡jfd|i|¤Ž t|ƒ¡}|jrh|  |¡n|rpt S|S| d¡jf||dœ|¤Žt |t ƒr®|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´NTrŽr4) r÷r rµrJrNrrFrr‘rßrwrr©rRrŽrÞr´r{rHr|rÄrÄrÅr^s$    zMaskedArray.allcCs²|tjurind|i}t|j|fi|¤Ž}|durt| d¡jfd|i|¤Ž t|ƒ¡}|jrh|  |¡n|rpt }|S| d¡jf||dœ|¤Žt |t ƒr®|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´NFrŽr4) r÷r rµrJrNr!rFrr‘rßrwrrr£rÄrÄrÅr!†s$    zMaskedArray.anycCst | d¡¡ ¡S)aü Return the indices of unmasked elements that are not zero. Returns a tuple of arrays, one for each dimension, containing the indices of the non-zero elements in that dimension. The corresponding non-zero values can be obtained with:: a[a.nonzero()] To group the indices by element, rather than dimension, use instead:: np.transpose(a.nonzero()) The result of this is always a 2d array, with a row for each non-zero element. Parameters ---------- None Returns ------- tuple_of_arrays : tuple Indices of elements that are non-zero. See Also -------- numpy.nonzero : Function operating on ndarrays. flatnonzero : Return indices that are non-zero in the flattened version of the input array. numpy.ndarray.nonzero : Equivalent ndarray method. count_nonzero : Counts the number of non-zero elements in the input array. Examples -------- >>> 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])) r)r÷r0rNr”rkrÄrÄrÅr”¤s`zMaskedArray.nonzerorÆc sZ|j}|tur,tƒj||||d}| |¡S|j|||d}| |¡ d¡jd|dSdS)z8 (this docstring should be overwritten) )ÚoffsetÚaxis1Úaxis2rÞ)r¤r¥r¦rrÇr4N)rJr“rnr¹rrFrNr´) rRr¤r¥r¦rrÞrër6rérsrÄrÅr¹s ÿ zMaskedArray.tracecCst||||dS)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 )rÞÚstrict)Údot)rRrÝrÞr§rÄrÄrÅr¨s%zMaskedArray.dotc CsÚ|tjurind|i}|j}t||fi|¤Ž}|durˆ| d¡j|fd|i|¤Ž}t|ddƒ} | r|| t|ƒ¡}|  |¡n|r„t }|S| d¡j|f||dœ|¤Ž}t |t ƒrÖt |ƒ} | turÐt|jƒ} |_|| _|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´Nrrr‘©rrÞ)r÷r rJrµrNr´ržrFrrßrwrrrYr“rur©rç© rRrŽrrÞr´r{rJr§r6ZrndimÚoutmaskrÄrÄrÅr´<s&'   zMaskedArray.sumcCsV| d¡j|||d}|dur8t|tƒr4| |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) r©rŽrrÞN) rNrCrrrßrHrFrrJ©rRrŽrrÞr6rÄrÄrÅrCzs    zMaskedArray.cumsumc CsÚ|tjurind|i}|j}t||fi|¤Ž}|durˆ| d¡j|fd|i|¤Ž}t|ddƒ} | r|| t|ƒ¡}|  |¡n|r„t }|S| d¡j|f||dœ|¤Ž}t |t ƒrÖt |ƒ} | turÐt|jƒ} |_|| _|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´NrÆrr‘rr©)r÷r rJrµrNr›ržrFrrßrwrrrYr“rur©rçrªrÄrÄrÅr›£s&   zMaskedArray.prodcCsV| d¡j|||d}|dur8t|tƒr4| |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 rÆr¬N)rNrBrrrßrJrFrr­rÄrÄrÅrBÍs   zMaskedArray.cumprodc sB|tjurind|i}|jtur>tƒjf||dœ|¤Žd}n´d}|durŠt|jjt j t j fƒrlt  d¡}nt|jjt j ƒrŠt  d¡}d}|jf||dœ|¤Ž}|jfd |i|¤Ž} | jdkrÌ| d krÌt}n&|ræ|j |d | ¡}n |d | }|dur>||_t|tƒr:t|ƒ} | tur0t|jƒ} |_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´r’rÄFNZf8Zf4TrŽrr—)r÷r rJr“rnrŠr=rrÚntypesÚintegerr¡ÚmuZfloat16r´rAr©rwrçrrrYru) rRrŽrrÞr´r{r6Zis_float16_resultZdsumÚcntr«rsrÄrÅrŠìs4        zMaskedArray.meancCs*| ||¡}|s||S|t||ƒSdS)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) N)rŠr )rRrŽrrërÄrÄrÅr#s zMaskedArray.anomc sºi}|tjur||d<|jturv|tjur2||d<tƒjf||||dœ|¤Žd}|durrt|tƒrn| t¡|S|S|j fd|i|¤Ž|} |tjur¢||} n||j ||dd} t |ƒrÎt   | ¡d } n| | 9} t| j|fi|¤Ž| ƒ t|ƒ¡} | jr,t|jj|fi|¤Ž| d kƒ| _|  |¡n^t| ƒrŠt} |durŠt|tƒrbd |_| d¡n$|jjd vr~d } t| ƒ‚ntj|_|S|dur¶| |_t|tƒr²| | 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´rŠ)rŽrrÞÚddofrÄNrŽT©r´r rÚbiuú>Masked data information would be lost in one or more location.)r÷r rJr“rnr¼rrrßrArŠrrXrrHr´rFrr‘rvrryrYrwrçrrrr‰rH) rRrŽrrÞr²r´rŠr{rÇr±ZdanomÚdvarr›rsrÄrÅr¼HsX   ÿÿ    "          zMaskedArray.varc Cs`|tjurind|i}|j||||fi|¤Ž}|tur\|durTtj|d|dd|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à?rƒ©rÞr…)r÷r r¼rwršr°) rRrŽrrÞr²r´rŠr{r¶rÄrÄrÅr²”szMaskedArray.stdcCsh|jj||d t|ƒ¡}|jdkr8|j|_| |¡n |jrBt}|durN|St|t ƒrd|  |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 Examples -------- >>> import numpy.ma as ma >>> x = ma.array([1.35, 2.5, 1.5, 1.75, 2.25, 2.75], ... mask=[0, 0, 0, 1, 0, 0]) >>> ma.round(x) masked_array(data=[1.0, 2.0, 2.0, --, 2.0, 3.0], mask=[False, False, False, True, False, False], fill_value=1e+20) )ÚdecimalsrÞrN) rDr¦rFrr‘rJryrwrrrß)rRr¸rÞr6rÄrÄrÅr¦¬s    zMaskedArray.round©ÚstablecCsn|r tdƒ‚|tjurt|ƒ}|durT|rLt |jtj¡rBtj}qTt|ƒ}nt |ƒ}|  |¡}|j |||dS)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``. stable : bool, optional Only for compatibility with ``np.argsort``. Ignored. 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]) ú6`stable` parameter is not supported for masked arrays.N©rŽrrõ) r,r÷r rÎrÃrrÄr‰rr‰rNr-)rRrŽrrõÚendwithr0rºrNrÄrÄrÅr-Ðs@ÿ   zMaskedArray.argsortr³cCsF|durt|ƒ}| |¡ t¡}|tjur.dnt|ƒ}|j|||dS)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]) NF©rÞr´)rrNrFrr÷r r¡r,©rRrŽr0rÞr´r|rÄrÄrÅr,&s )zMaskedArray.argmincCsH|durt|jƒ}| |¡ t¡}|tjur0dnt|ƒ}|j|||dS)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¾) r‰rDrNrFrr÷r r¡r+r¿rÄrÄrÅr+Us ! zMaskedArray.argmaxrÇcCsd|r tdƒ‚|jtur,tj||||ddS|tur8dS|j|||||d}tj|||d|d<dS)ah 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``. stable : bool, optional Only for compatibility with ``np.sort``. Ignored. 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) r»r¼N)rŽrrõr0r½r!.) r,rJr“rr¯rwr-r÷Ztake_along_axis)rRrŽrrõr½r0rºZsidxrÄrÄrÅr¯|sIÿ  ÿzMaskedArray.sortc Cs |tjurind|i}|j}t||fi|¤Ž}|dur>t|ƒ}|dur¢| |¡jf||dœ|¤Ž t|ƒ¡}|j r–|  |¡|j ržtj ||j |dn|ržt }|S| |¡jf||dœ|¤Ž}t|tƒrðt|ƒ} | turèt|jƒ} |_|| _n,|jjdvr d} t| ƒ‚tj |tj|d|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´Nr4rwr´rµ)r÷r rJrµrrNr‹rFrr‘rßrxr0rwrrrYr“rur©rçrrrr‰© rRrŽrÞr0r´r{rJr§r6r«r›rÄrÄrÅr‹Ös>A ÿÿÿ  zMaskedArray.minc Cs |tjurind|i}|j}t||fi|¤Ž}|dur>t|ƒ}|dur¢| |¡jf||dœ|¤Ž t|ƒ¡}|j r–|  |¡|j ržtj ||j |dn|ržt }|S| |¡jf||dœ|¤Ž}t|tƒrðt|ƒ} | turèt|jƒ} |_|| _n,|jjdvr d} t| ƒ‚tj |tj|d|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´Nr4rwr´rµ)r÷r rJrµr‰rNr‡rFrr‘rßrxr0rwrrrYr“rur©rçrrrr‰rÀrÄrÄrÅr‡9s>H ÿÿÿ  zMaskedArray.maxcCsj|dur0|j|||d}||j|||d8}|S|j||||d|_|j|||d}tj|||dd|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=np.int64(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=np.int64(999999), dtype=uint8) N)rŽr0r´)rŽrÞr0r´rƒr·)r‡r‹rçr÷r³)rRrŽrÞr0r´r6Z min_valuerÄrÄrÅr¤s Kÿ ÿ ÿÿzMaskedArray.ptpcs,tjd|jj›dddtƒj|i|¤ŽS)Nz3Warning: 'partition' will ignore the 'mask' of the rr rÉ)rËrÌrtrÁrnÚ partition©rRrzr{rsrÄrÅrÁüs ÿþzMaskedArray.partitioncs,tjd|jj›dddtƒj|i|¤ŽS)Nz6Warning: 'argpartition' will ignore the 'mask' of the rr rÉ)rËrÌrtrÁrnÚ argpartitionrÂrsrÄrÅrÃs ÿþzMaskedArray.argpartitionc Csª|j|j}}t|ƒ}t|ƒ}|tur0| d¡}|durT|j|||dd |¡}ntj|||||dt |t ƒr¢|tur€|} n|j|||d} | |O} |  | ¡|dS)z rN)rŽrž.)rŽržrÞrÄ) rDrJrrYr“rNr¶rFr÷rrrß) rRrarŽrÞržrDrJr@Z maskindicesr«rÄrÄrÅr¶s   zMaskedArray.taker=rFÚflattenr¢r±rµcCs| ¡Sr)rºrkrÄrÄrÅÚ)rýzMaskedArray.rºcCsB|jdkrtdƒ‚|jtur*t|jjdSt|jj|jjdSdS)a( Return the matrix-transpose of the masked array. The matrix transpose is the transpose of the last two dimensions, even if the array is of higher dimension. .. versionadded:: 2.0 Returns ------- result: MaskedArray The masked array with the last two dimensions transposed Raises ------ ValueError If the array is of dimension less than 2. See Also -------- ndarray.mT: Equivalent method for arrays r z+matrix transpose with ndim < 2 is undefined)rG)rGrHN) r‘r,rJr“rxrDÚmTrGrHrkrÄrÄrÅrÆ,s   zMaskedArray.mTcCs´|j}|tur|j ¡S|dur.| |¡ ¡S|jj}|rr|j dd„|Dƒ¡}|D]}d||||<qT| ¡S|tur€dgS|j}t j |j  ¡t d}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]] NcSsg|] }|tf‘qSrÄ)r-r²rÄrÄrÅrütrýz&MaskedArray.tolist..r ) rJr“rDÚtolistrNrr rr©r÷r r r-)rRr0rJr r6r(rÝrÄrÄrÅrÇOs$  zMaskedArray.tolistcCstjdtdd|j||dS)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.r rÉr˜)rËrÌr2Útobytes©rRr0rõrÄrÄrÅÚtostring‚s þzMaskedArray.tostringcCs| |¡j|dS)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ÉrÄrÄrÅrÈ‘s&zMaskedArray.tobytesrÏú%scCs tdƒ‚dS)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.Nr*)rRZfidÚseprKrÄrÄrÅÚtofile¹s zMaskedArray.tofilecCs\|j}|j}|dur t|j|ƒ}|jj}tj|jd|fd|fgd}|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', 'B  U(b  '> )( 7 %ÿJ ÿ  $ ÿÿ Vÿ /ÿ 'ÿÿ Zck X    " 3  ( : rcCs2t |||¡}t t|t|ƒ¡}|j||||dS)zbInternal function that builds a new MaskedArray from the information stored in a pickle. )rHr)rrrt)rr.Z baseshapeÚbasetyperDrJrÄrÄrÅr×8sr×cs|eZdZdZedddddfdd„Ze‡fdd„ƒZd d „Zd d „Z ‡fd d„Z e Z dd„Z dd„Z ddd„Zdd„Z‡ZS)rzN Fake a 'void' object to use for masked array with structured dtypes. NFTc Csœ|sdnd}tj||||d}| |¡}||_|turŠt|tjƒrJ||_n@zt |¡|_Wn.tyˆt |ƒ} tj|| dd|_Yn0|dur˜||_ |S)NT)r=rCrr rÄ) r÷r rFrír“rr+rJrÖrtr0) rRrGrHrr0rër=rCrDrürÄrÄrÅrGs    z mvoid.__new__cs tƒjdS)NrÄ)rnrDrkrsrÄrÅrD\sz mvoid._datacCsT|j}t||tƒr6t|j||||j||jdS|turJ||rJtS|j|S)z! Get the index. )rGrHr0r) rJrrrxrDrrír“rw)rRrîrërÄrÄrÅrìasýzmvoid.__getitem__cCsB||j|<|jr,|j|t|ddƒO<nt|ddƒ|j|<dS)NrJF)rDrírJrž)rRrîrºrÄrÄrÅrðws zmvoid.__setitem__csN|j}|turt|jƒSt|jjdƒ}tƒj}| |¡}t||jt ƒt|ƒS)Nrá) rJr“rrDrrrnrrÓrƒ)rRrër:Zdata_arrrÈrsrÄrÅrl~s  z mvoid.__str__ccsL|j|j}}|tur"|EdHn&t||ƒD]\}}|r@tVq,|Vq,dS)zDefines an iterator for mvoidN)rDrJr“r%rw)rRrDrJr|rërÄrÄrÅr­‹s zmvoid.__iter__cCs |j ¡Sr)rDÚ__len__rkrÄrÄrÅrâ—sz mvoid.__len__cCst|ƒ |¡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)rRr0rÄrÄrÅrNšsz mvoid.filledcCsZ|j}|tur|j ¡Sg}t|j|jƒD]&\}}|rB| d¡q*| | ¡¡q*t|ƒS)z¤ Transforms the mvoid object into a tuple. Masked fields are replaced by None. Returns ------- returned_tuple Tuple of fields N)rJr“rDrÇr%r"r'r )rRrJr6r|rërÄrÄrÅrDzs   z mvoid.tolist)N)rÁrÂrÃrÛr“rrÝrDrìrðrlrÒr­rârNrÇrrÄrÄrsrÅrBsÿ    rcCs t|tƒS)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 )rr©rZrÄrÄrÅreÏs0recs¤eZdZdZedd„ƒZdd„Z‡fdd„Zdd d „Zd d „Z d d„Z dd„Z dd„Z dd„Z e ZZZZZZ[ dd„Zdd„Zdd„Z‡fdd„Z‡ZS)r<NcCs|jduot|jƒ|uSr)Ú_MaskedConstant__singletonr)r@rÄrÄrÅZ__has_singleton szMaskedConstant.__has_singletoncCsF| ¡s@t d¡}t d¡}d|j_d|j_t||d |¡|_|jS)Nr–TFrª)Ú_MaskedConstant__has_singletonr÷r rZ writeablerrFrä)r@rGrHrÄrÄrÅrs  zMaskedConstant.__new__cs6| ¡stƒ |¡S||jur nt|_t ||¡dSr)rårnrrärrt)rRr×rsrÄrÅr"s   z!MaskedConstant.__array_finalize__FcCs| t¡ ||¡Sr)rFrr)rRr×rrrÄrÄrÅr0szMaskedConstant.__array_wrap__cCs ttjƒSr)rrƒrÊrkrÄrÄrÅrl3szMaskedConstant.__str__cCs|tjurdSt |¡SdS)Nrw)r<rär-rÒrkrÄrÄrÅrÒ6s zMaskedConstant.__repr__cCsBzt ||¡WSty<tjdtddt |d¡YS0dS)NzjFormat strings passed to MaskedConstant are ignored, but in future may error or produce different behaviorr rÉrÏ)r-Ú __format__rÖrËrÌÚ FutureWarning)rRÚ format_specrÄrÄrÅræ=s ýzMaskedConstant.__format__cCs |jdfS)z.Override of MaskedArray's __reduce__. rÄrsrkrÄrÄrÅrÐLszMaskedConstant.__reduce__cCs|SrrÄrbrÄrÄrÅÚ__iop__SszMaskedConstant.__iop__cOs|S)z: Copy is a no-op on the maskedconstant, as it is a scalar rÄrÂrÄrÄrÅr=^szMaskedConstant.copycCs|SrrÄrkrÄrÄrÅÚ__copy__dszMaskedConstant.__copy__cCs|SrrÄ)rRrÙrÄrÄrÅrÜgszMaskedConstant.__deepcopy__csD| ¡stƒ ||¡S||jur2td|›dƒ‚ntƒ ||¡SdS)Nzattributes of z are not writeable)rårnÚ __setattr__rärE)rRÚattrrºrsrÄrÅrëjs  ÿzMaskedConstant.__setattr__)NF)rÁrÂrÃräÚ classmethodrårrrrlrÒrærÐrér|rr€r…r†r‡r=rêrÜrërrÄrÄrsrÅr<s4   úÿþýr<c Cst||||| |||| ||d S)z~ Shortcut to MaskedArray. The options are in a different order for convenience and backwards compatibility. ) rHrr=rCrrr0rör¢rõ)r) rGrr=rõrHr0rrr¢rCrörÄrÄrÅr {s ýr cCs$t|ƒ}|turdS| ¡r dSdS)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)rYr“r!)rZrërÄrÄrÅrgŒs -rgcs>eZdZdZ‡fdd„Zdd„Zejfdd„Zdd „Z ‡Z S) Ú_extrema_operationzœ Generic class for maximum/minimum functions. .. note:: This is the base class for `_maximum_operation` and `_minimum_operation`. cstƒ |¡||_||_dSr)rnrSr^Úfill_value_func)rRrjr^r0rsrÄrÅrSÏs z_extrema_operation.__init__cCst| ||¡||ƒS)r`)r½r^rQrÄrÄrÅr[Ôsz_extrema_operation.__call__cCsêt|ddd}t|ƒ}|tjurP|jdkrPtjd|j›d|j›dtdd d}|tjurft |d }nt ƒ}|t urŠ|j j |fi|¤Ž}n\|  | |¡¡ t|ƒ¡}|j j |fi|¤Ž}tjj |fi|¤Ž}t|d ƒrÞ||_n|ræt}|S) z#Reduce target along the given axis.NTrBrÆz!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.r rÉr!rJ)r3rYr÷r r‘rËrÌrÁrÀr:r“rßrrNrïrFrrXrorrJrw)rRrrŽrër{rrÄrÄrÅrÙs6 ÿü  ÿÿ z_extrema_operation.reducecCsvt|ƒ}t|ƒ}|tur&|tur&t}nt|ƒ}t|ƒ}t ||¡}|j t|ƒt|ƒ¡}t|tƒsl|  t¡}||_ |S)zs z_frommethod.__init__cCsNtt|jdƒptt|jdƒ}|jt|ƒ}|durJd|t|ddƒf}|SdS)ú>> 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.2988071523335984, 15.784728999999999, 1.0, --], mask=[False, False, False, True], fill_value=1e+20) Nz3-argument power not supported.rUrv)rrYrvrXrrrr÷rWr½rXršrFryrprIrr“r‘rwrqrJr!r0rD) r5rÝÚthirdr‰rŠrëÚfaÚfbrár6rKrÄrÄrÅrš€s2+   :    ršr,r+r¹cCsRt |¡}|tjurt|ƒ}t|tƒr<|j|||||ddS|j|||ddSdS)z)Function version of the eponymous method.N©rŽrrõr½r0rº©rŽrrõrº)r÷r/r rÎrrr-©r5rŽrrõr½r0rºrÄrÄrÅr-Ðs    ÿr-rÇcCs\tj|ddd}|dur$| ¡}d}t|tƒrF|j||||||dn|j||||d|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) TrBNrrr)r÷r rÄrrr¯rrÄrÄrÅr¯às  ÿr¯cCs t|ƒ ¡S)ac 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/r9rãrÄrÄrÅr9 s#r9cCsvt dd„|Dƒ|¡}t|Ž}| |¡}|D]}t|ƒtur,qFq,|St dd„|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) cSsg|] }t|ƒ‘qSrÄ)rXr;rÄrÄrÅrüYrýzconcatenate..cSsg|] }t|ƒ‘qSrÄrr;rÄrÄrÅrücrý) r÷r:rArFrYr“r£r©r rJ)r>rŽr|r?rGrZÚdmrÄrÄrÅr:0s)    r:cCs2t ||¡ t¡}t|ƒtur.t |j|¡|_|S)az Extract a diagonal or construct a diagonal array. This function is the equivalent of `numpy.diag` that takes masked values into account, see `numpy.diag` for details. See Also -------- numpy.diag : Equivalent function for ndarrays. Examples -------- Create an array with negative values masked: >>> 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) )r÷rErFrrYr“rJ)rÛrûr»rÄrÄrÅrEls, rEcCsJt|ƒ}|tur(t t|ƒ|¡}t|ƒSt t|dƒ|¡}t||dSdS)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ªN)rYr“rXrirNrx©r5r(rër|rÄrÄrÅrižs ricCsJt|ƒ}|tur(t t|ƒ|¡}t|ƒSt t|dƒ|¡}t||dSdS)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ªN)rYr“rXr¥rNrxrrÄrÄrÅr¥³s r¥cCs@z|j|||dWSty:t |¡j|||dYS0dS)zÈ Set storage-indexed locations to corresponding values. This function is equivalent to `MaskedArray.put`, see that method for details. See Also -------- MaskedArray.put rN)ržrEr÷r0)r5rarŸržrÄrÄrÅrž×s  ržcCsÔt|tƒs| t¡}t|ƒt|ƒ}}t|ƒturd|tur¾d|_t|j|j ƒ|_ t j |j ||dnZ|j rœ|tur¾|j  ¡}t j |||d|j|O_n"|tur¬t|ƒ}t j |j ||dt j |j||ddS)aÍ 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`. Examples -------- >>> arr = [[1, 2], [3, 4]] >>> mask = [[1, 0], [0, 0]] >>> x = np.ma.array(arr, mask=mask) >>> np.ma.putmask(x, x < 4, 10*x) >>> x masked_array( data=[[--, 20], [30, 4]], mask=[[ True, False], [False, False]], fill_value=999999) >>> x.data array([[10, 20], [30, 4]]) TrwN)rrrFrXrYr“rrur©rrJr÷rxrír=rHrZrD)r5rHrŸZvaldataZvalmaskrërÄrÄrÅrŸês$#    rŸcCs:z | |¡WSty4t |¡ |¡ t¡YS0dS)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) N)rºrEr÷r0rFr)r5r‘rÄrÄrÅrº"s   rºrcCsFz|j||dWSty@t |¡j||d}| t¡YS0dS)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 r˜N)r£rEr÷r0rFr)r5Ú new_shaperõZ_tmprÄrÄrÅr£Hs  r£cCsBt|ƒ}|turt ||¡}t ||¡ 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) )rYr“r÷r¤rFrAr‘rJ)rZrrër6rÄrÄrÅr¤[s7 r¤cCst t|ƒ¡S)z5 maskedarray version of the numpy function. )r÷r‘rXrrÄrÄrÅr‘›sr‘cCst t|ƒ¡S©ú*maskedarray version of the numpy function.)r÷r©rXrrÄrÄrÅr©¥sr©cCst t|ƒ|¡Sr)r÷r¬rX)r×rŽrÄrÄrÅr¬«sr¬cCs|dkr |S|dkr$tdt|ƒƒ‚tj |¡}|jdkrBtdƒ‚g}|tjur’tj |¡}|jdkrˆt|jƒ}d||<t  |t |ƒ¡}|  |¡|  |¡|tjurètj |¡}|jdkrÞt|jƒ}d||<t  |t |ƒ¡}|  |¡t |ƒdkrtj  ||¡}t |||¡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=np.int64(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=np.int64(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Æ)r,rQr÷r‰r/r‘r rLr©r]r r"r$r:rG)r5r(rŽÚprependr"Úcombinedr©rÄrÄrÅrG±s8b  ÿ           rGc Cs|tu|tuf d¡}|dkr&tdƒ‚|dkr6t|ƒSt|dƒ}t|ƒ}t|ƒ}t|ƒ}t|ƒ}t|ƒ} |turš|turštj d|j d}tj d| j d}n0|turÊ|turÊtj d|j d}tj d|j d} t  |||¡} t  ||| ¡} t  |tj d| j d| ¡} t | ƒ} t| | dS) a¡ Return a masked array with elements from `x` or `y`, depending on condition. .. note:: When only `condition` is provided, this function is identical to `nonzero`. The rest of this documentation covers only the case where all three arguments are provided. Parameters ---------- condition : array_like, bool Where True, yield `x`, otherwise yield `y`. x, y : array_like, optional Values from which to choose. `x`, `y` and `condition` need to be broadcastable to some shape. Returns ------- out : MaskedArray An masked array with `masked` elements where the condition is masked, elements from `x` where `condition` is True, and elements from `y` elsewhere. See Also -------- numpy.where : Equivalent function in the top-level NumPy module. nonzero : The function that is called when x and y are omitted Examples -------- >>> 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) TrÆz)Must provide both 'x' and 'y' or neither.r FrÄr rª)r rAr,r”rNrXrZrwr÷r¾rr–r½r rx) r¸rZr1ÚmissingrÑZxdZydÚcmZxmZymrGrHrÄrÄrÅr½=s,8 r½c s¬dd„‰dd„‰t|dƒ}‡fdd„|Dƒ}‡fdd„|Dƒ}tj|||d }tt|t|ƒƒd d d }tj||||d  t¡}|duržt|tƒrš|  |¡|S|  |¡|S)aH Use an index array to construct a new array from a list of choices. Given an array of integers and a list of n choice arrays, this method will create a new array that merges each of the choice arrays. Where a value in `index` is i, the new array will have the value that choices[i] contains in the same place. Parameters ---------- indices : ndarray of ints This array must contain integers in ``[0, n-1]``, where n is the number of choices. choices : sequence of arrays Choice arrays. The index array and all of the choices should be broadcastable to the same shape. out : array, optional If provided, the result will be inserted into this array. It should be of the appropriate shape and `dtype`. 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 Returns ------- merged_array : array See Also -------- choose : equivalent function Examples -------- >>> 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) cSs|tur dSt|ƒS)z,Returns the filled array, or True if masked.T)rwrNrãrÄrÄrÅÚfmaskÅszchoose..fmaskcSs|tur dSt|ƒS)z:Returns the mask, True if ``masked``, False if ``nomask``.T)rwrYrãrÄrÄrÅÚnmaskËszchoose..nmaskrcsg|] }ˆ|ƒ‘qSrÄrÄ©rúrZ)r rÄrÅrüÓrýzchoose..csg|] }ˆ|ƒ‘qSrÄrÄr)r rÄrÅrüÔrýrFTr¨)ržrÞN) rNr÷r5rsrvrYrFrrrß) raÚchoicesrÞržrÞZmasksrGZ outputmaskr|rÄ)r r rÅr5˜s - ÿ   r5cCsD|durt |||¡St t|ƒ||¡t|dƒr>> 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) NrJ)r÷r¦rXrrYrJ)r5r¸rÞrÄrÄrÅr§ãs .  r§cCsnt|dd}t|ƒ}|tus,| ¡r,|dur0|S|j ¡|_t||jƒ}|D]}|j|j|ddO_qL|S)zH Mask whole 1-d vectors of an array that contain masked values. FrXNT)rŽr´)r rYr“r!rJr=rr‘)r5rŽrër‘r—rÄrÄrÅÚ_mask_propagates   rc CsN|durrt |¡dksrt |¡dkr&nL|jdkrRt||jdƒ}t||jdƒ}n t||jdƒ}t||jdƒ}t|ƒ}t|ƒ}|durêt t|dƒt|dƒ¡}t ||¡}t |¡dkrÌt |¡}| t||ƒ¡}|  |¡|St t|dƒt|dƒ|j ¡}|j j |j kr&t  |j t¡|_t |||j¡t |j|j¡|SdS)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) TrrÆr N)r÷r‘rrZr¨rNr0rFrArßrDrHr©rIrrJrp) r5rÝr§rÞÚamZbmr|rëršrÄrÄrÅr¨-s05     r¨cCsFt|dƒ}t|dƒ}|jdkr$d|_|jdkr4d|_t ||¡ 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Œ)rNr‘r©r÷rbrFr)r5rÝrþrÿrÄrÄrÅrbs    rbz Masked values are replaced by 0.cCsŒt|dƒ ¡}t|dƒ ¡}t ||¡}t|ƒ}t|ƒ}|turP|turPt|ƒSt|ƒ}t|ƒ}tdt d|d|¡dd}t||dS)rrrÆFr‹rª) rNr r÷r˜rYr“rxrZrs)r5rÝrþrÿr|r‰rŠrërÄrÄrÅr˜“s  r˜cCs¢|r`|t|ƒtjt |¡td|d|tjt |¡tdt|ƒ|dB}|t|ƒt|ƒ|d}n6|t|ƒt|ƒ|d}|t|dƒt|dƒ|d}t||dS)z: Helper function for ma.correlate and ma.convolve r rrrª)rZr÷r–r©r¡rXrNrx)rßr5rÛržÚpropagate_maskrHrGrÄrÄrÅÚ_convolve_or_correlate¥s  ÿÿrÚvalidcCsttj||||ƒ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. )rr÷r>©r5rÛržrrÄrÄrÅr>¸sr>r cCsttj||||ƒ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. )rr÷r<rrÄrÄrÅr<Ôsr<cCs„tt|ƒt|ƒƒ}|tur>t|ƒ}t|ƒ}t ||¡}| ¡S|r|t|ƒ}t|ƒ}t ||¡}t||dd}| d¡ d¡SdSdS)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)rHr=TN) rvrYr“rXrXrKrr rN)r5rÝr0rërZr1r|rrÄrÄrÅrðs*  rc Cs,t|dd}t|dd}|jjdkrHt |d¡}|j|krHt||dd}tt|ƒt|ƒƒ}t t|d|d¡ d¡} t  | tt |¡dƒk¡s’dSt  | ¡sÊtt t ||ƒ||t |ƒƒ|ƒ} t  | ¡St  t|| || k|ƒ¡sêdS|| }|| }tt t ||ƒ||t |ƒƒ|ƒ} t  | ¡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 Fr‹rër—)rr=)r=rH) rxrrr÷Z result_typervrYÚisinfrNrr!rkr) r5rÝryrÂrÁrZr1rrëZxinfr|rÄrÄrÅr* s.H      ÿ   ÿrcCs|pd}t||ddd|dS)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=rrCrõ©rx)r5rrõrÄrÄrÅr0– s, ÿr0cCs2t|tƒr |dus||jkr |St||ddddS)a` 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=rrC)rrrrx)r5rrÄrÄrÅr/Ç s,r/rÏcCs tdƒ‚dS)Nz1fromfile() not yet implemented for a MaskedArray.r*)ÚfilerrArÌrÄrÄrÅÚfromfileý sÿrcCst|d|ddS)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=np.int64(999999), dtype=int32) rDrJrªr)ZfxarrayrÄrÄrÅrV!s=rVc@s6eZdZdZdZd dd„Zdd„Zdd„Zd d „ZdS) Ú _convert2maz Convert functions from numpy to numpy.ma. Parameters ---------- _methodname : string Name of the method to transform. NcCs(tt|ƒ|_| ||¡|_|p i|_dSr)ržr÷Ú_funcrôrÛÚ_extras)rRrâÚnp_retÚ np_ma_retràrÄrÄrÅrSO!s z_convert2ma.__init__cCsJt|jddƒ}t|jƒ}|rF| |||¡}|r>d|jj|f}||}|S)r÷rÛNz%s%s )ržrrÙÚ_replace_return_typerÁ)rRrrrúrØrÄrÄrÅrôT!s z_convert2ma.getdocc CsD||vr8td|›d|›d|›d|jj›d|jj›d ƒ‚| ||¡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.)r"rrÁÚreplace)rRrúrrrÄrÄrÅr`!sÿþýÿz _convert2ma._replace_return_typecOsx|j}t|ƒ |¡}|D]}| |¡||<q|jj|i|¤Ž t¡}d|vrZ| dd¡|_ d|vrtt | dd¡ƒ|_ |S)Nr0rërF) rÚsetÚ intersectionÚpoprr[rFrrr0r¡rí)rRrzràrZ common_paramsÚpr6rÄrÄrÅr[|!sz_convert2ma.__call__)N)rÁrÂrÃrÛrSrôrr[rÄrÄrÄrÅrB!s    rr#)r0rëzarange : ndarrayzarange : MaskedArray)ràrrr6zclipped_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 MaskedArraysr–r—r±zsqueezed : ndarrayzsqueezed : MaskedArrayr¾r¿cCst||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:)r5rÝrŽrÄrÄrÅr"×!s(r")N)T)N)FT)T)T)T)T)T)T)T)T)T)TT)r¿rÀTT)T)T)NNrœ)N)rÇNNTN)r)r)rœ)N)r)N)Nrœ)rN)FN)rT)r T)T)Tr¿rÀ)NN)N)N(+rÛrMrÒrYrËÚtextwraprÐÚ functoolsrÚtypingrÚnumpyr÷Znumpy._core.umathrOrXZnumpy._core.numerictypesZ numerictypesr®Z numpy._corerr°rrrrr r r r r3r rrZnumpy._core.numericrZnumpy._utils._inspectrrZ numpy._utilsrÚ__all__r¡rr“rçrÀrÎrÕrÙr†rrrrÛZ datetime64Z timedelta64ZhalfÚsingleÚdoubleZ longdoubleZcsingleZcdoubleZ clongdoubleZfloat_types_listrórr&Ú__annotations__rôZ sctypeDictrŸZsctyperZ scalar_dtyperZint64Úinfor‹r‡Zmin_valZmax_valrÃr¯rÄr#r r"rrrDr!rr‰r&r3r¨r7r7rNrArXÚget_datarOrOrqrrrPr]rardrhrirmr€r”rLr;rªr?r(r'r«r@r¸rrrMr’rRr4r.rpr°rlrnrmr·r&r$r%r*rr³rr)rKr•rkr\rjr[rorrqr®rrr1r2r3r^rHr»rSr¡rTrŽr˜rrtrYZget_maskrZrfr rsrur¤rvrPrµr†rzr{r~rr€ryr|r‚rr…r}rÉrƒrÓr:ÚdedentrPrÔrQrårærr×rrerhrdr<rwr„rxrgrîrrórr rr!r8rBrCr=rFr]r`rˆrŠrŒr”r›rœr r¢rÆr­r²r´rµr¹r¼rAr¶ršr,r+r-r¯r9r:rErir¥ržrŸrºr£r¤r‘r©r¬rGr½r5r§r¦rr¨rbrcr˜r™rr>r<rrr0r/rcrrVrr#r6rIrJrUrWr_rar–r—r±r¾r¿r"rÄrÄrÄrÅÚsV   $  $ø  ÿ         733 ,A  : 3:  JL               ÿÿÿÿÿÿÿÿÿ               ÿÿÿ !;5D Z 2 88 z      ( ( D H (0ë"7 -l3 3q þ :C   )    M ÿÿ  ÿ *& < 2$  8&@ [K5R ÿ ÿ:l16@J ü  ü  ü ý ý ý  ü  ü  ü ý  ü  ü ý