2[c@`s|dZddlmZmZmZddlZddlZddlZddlZddl Z ddl m Z ej ddkrddl Z n ddlZ ddlZddljjZddljjZddlmZmZmZmZmZmZddlmZddlm Z dd l!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'dd lm(Z)dd l*m+Z+dd l,m-Z-ej ddkrddl.Z.n ddl/Z.d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddgZ0ejZ1e1dZ2de3fdYZ4dZ5dZ6dZ7d e8fdYZ9de9fdYZ:i e;d6ddd6dd6dd6dd6dd6dd6dd6dd6Z<xqdddddddddddddg D]BZ=ej>de=e<de=dZdefd?YZd@ZeZeZdAefdBYZeZZeZeVeeVe2eVe;ee;e;ddC Zeje_dDZdEedfdFYZeVeVeVejdGZejje_eVeVeVejdHZejje_eVeVeVejdIZejje_dJe^fdKYZedZedZZedZed6dLe;Zed@ZedAZed;ZedDZed^ZedaZeejeePZedZeejeeOZedZedZedZedZedZedMZedZedZedZedZedZedZed?ZeVeVdNdOZeVdPZed(Zed'ZejdQeVe;eVdRZejje_dSdQeVe;eVdTZejje_dUZddVZddWZdXZ(dYZdZZdNd[Zd\ZeVd]Zd^d_Zd`ZdaZejje_dbZejje_dcZejje_eVddZejje_eedeZeVdNdfZdeVdgZxexZeVdhZeeVdiZdjZe6ejjdke_eZdlZe6ejjdke_eZdmZdne;doZ dpe;dqZ e;drZ e;d(d)dsZ eVeVdtZ eVduZdvZdwZdxZdyZdzZedSd{d|Zd}Zd~e^fdYZeddedeVdeZejZejZedIdedeVdeZedJZedVZedXZed`dedeVdeZej Z eddedeVdeZ!ej"Z"ej#Z#eddedeVdeZ$ej%Z%eVdZ&dS(s 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 i(tdivisiontabsolute_importtprint_functionN(treducei(tndarraytamaxtamint iscomplexobjtbool_t_NoValue(tarray(tangle(t getargspect formatargspectlongt basestringtunicodetbytes(t expand_dims(tnormalize_axis_index(tnormalize_axis_tupletMAErrort MaskErrortMaskTypet MaskedArraytabstabsolutetaddtalltallclosetallequaltalltrueRRR tanomt anomaliestanytappendtarangetarccostarccoshtarcsintarcsinhtarctantarctan2tarctanhtargmaxtargmintargsorttaroundR t asanyarraytasarrayt bitwise_andt bitwise_ort bitwise_xorRtceiltchoosetcliptcommon_fill_valuetcompresst compressedt concatenatet conjugatetconvolvetcopyt correlatetcostcoshtcounttcumprodtcumsumtdefault_fill_valuetdiagtdiagonaltdifftdividetdumptdumpstemptyt empty_liketequaltexpRtfabstfilledt fix_invalidt flatten_masktflatten_structured_arraytfloort floor_dividetfmodt frombuffertfromflext fromfunctiontgetdatatgetmaskt getmaskarraytgreatert greater_equalt harden_maskthypottidentitytidstindicestinnert innerproducttisMAt isMaskedArraytis_maskt is_maskedtisarrayt left_shifttlesst less_equaltloadtloadstlogtlog10tlog2t logical_andt logical_nott logical_ort logical_xort make_masktmake_mask_descrtmake_mask_nonetmask_ortmaskedt masked_arrayt masked_equaltmasked_greatertmasked_greater_equalt masked_insidetmasked_invalidt masked_lesstmasked_less_equaltmasked_not_equalt masked_objecttmasked_outsidetmasked_print_optiontmasked_singletont masked_valuest masked_wheretmaxtmaximumtmaximum_fill_valuetmeantmintminimumtminimum_fill_valuetmodtmultiplytmvoidtndimtnegativetnomasktnonzerot not_equaltonestoutert outerproducttpowertprodtproducttptptputtputmasktranktravelt remaindertrepeattreshapetresizet right_shifttroundtround_tset_fill_valuetshapetsintsinhtsizet soften_masktsometruetsorttsqrttsqueezetstdtsubtracttsumtswapaxesttakettanttanhttracet transposet true_dividetvartwheretzerostMaskedArrayFutureWarningcB`seZRS((t__name__t __module__(((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR_scC`s1|jdkrdStjdtdddSdS(s 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 compatibiity. Thankfully, this only makes a difference when arrays are 2- or more- dimensional, so we only need a warning then. iisIn 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.t stackleveliN(RtwarningstwarnRtNone(tarr((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt_deprecate_argsort_axisbs  cC`s|dkrdS|dkr |Stjd|}d|}t|dkr_d|d}ndj|d |g|dS(s9 Adds a Notes section to an existing docstring. Ns\n\s*?Notes\n\s*?-----sNotes ----- %sis s t(Rtretsplittlentjoin(t initialdoctnotet notesplittnotedoc((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pytdoc_note~s   cC`s4ytt|}Wntk r/d}nX|S(s% Get the signature from obj R(R R t TypeError(tobjtsig((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pytget_object_signatures   cB`seZdZRS(s1 Class for masked array related errors. (RRt__doc__(((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRscB`seZdZRS(s) Class for mask related errors. (RRR(((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRstbg@xDytctfi?Btit?tOsN/AtStus???tVuN/AtUtYtMtWtDthtmtstmstustnstpstfstastNaTsM8[t]sm8[tfloat128c`sjrBtfdjD}tj|ddSjryj\}}t|}tj||SSdS(sR Recursively produce a fill value for `dtype`, calling f on scalar dtypes c3`s"|]}t|VqdS(N(t_recursive_fill_value(t.0tname(tdtypeR(s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pys sRN((tnamesttupletnpR tsubdtypeRtfull(RRtvalstsubtypeRtsubval((RRs,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs " cC`s@t|tjr|St|dr,|jStj|jSdS(s4 Convert the argument for *_fill_value into a dtype RN(t isinstanceRRthasattrR0(R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt _get_dtype_ofs cC`s"d}t|}t||S(sN 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) cS`s=|jdkr&tj|jddStj|jdSdS(NtMmiR(tkindtdefault_fillertgettstr(R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt_scalar_fill_values(RR(RR R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyREs-  c`s+fd}t|}t||S(Nc`s<y |SWn)tk r7tdj|nXdS(Ns&Unsuitable type {} for calculating {}.(tKeyErrorRtformat(R(textremumt extremum_name(s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR (s   (RR(RR RR R((R Rs,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt_extremum_fill_value&s cC`st|tdS(s` 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(Rt min_filler(R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR5s0cC`st|tdS(sd 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(Rt max_filler(R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRhs0cC`stj|t|j}g}xt||jD]y\}}||}|jrc|jd}n|jr|jtt||q4|jtj |d|j q4Wt|S(s 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. iR( RRRRtzipRR#Rt_recursive_set_fill_valueR titem(t fillvaluetdtt output_valuetfvalRtcdtype((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs   &cC`stj|}|j}|d kr3t|}nV|rg|jD]}|d|df^qC}t|ttjfrytj |dt d|}Wqt k rd}t |||fqXqtj |dt }tj t||d|}nt|tr:|jdkr:d}t||nOytj |dt d|}Wn-tk rd}t|||fnXtj |S( s 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. iiR>Rs"Unable to transform %s to dtype %stOSVUs6Cannot set fill value of string with array of dtype %ss Fill value %s overflows dtype %sN(RRtfieldsRREtdescrRRtvoidR tFalset ValueErrorR1tobjectRRtcharRt OverflowError(t fill_valuetndtypeRt_tfdtypeterr_msg((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt_check_fill_values0   *   cC`s#t|tr|j|ndS(s 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 = 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(taR#((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs<cC`s+t|tr|j}n t|}|S(sr Return the filling value of a, if any. Otherwise, returns the default filling value for that type. (RRR#RE(R)tresult((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pytget_fill_value's  cC`s,t|}t|}||kr(|SdS(s 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(R+R(R)Rtt1tt2((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR84s    cC`s_t|dr|j|St|tr/|St|trNtj|dStj|SdS(sn 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 : scalar, optional Filling value. Default is None. Returns ------- a : ndarray The filled array. See Also -------- compressed Examples -------- >>> x = np.ma.array(np.arange(9).reshape(3, 3), mask=[[1, 0, 0], ... [1, 0, 0], ... [0, 0, 0]]) >>> x.filled() array([[999999, 1, 2], [999999, 4, 5], [ 6, 7, 8]]) RQRN(RRQRRtdictRR (R)R#((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRQTs# cG`st|dkrC|d}t|tr:t|}qt}nng|D]}t|^qJ}|d}t|tst}nx*|dD]}t||r|}qqW|jdkrtS|S(s Return the youngest subclass of MaskedArray from a list of (masked) arrays. In case of siblings, the first listed takes over. iitMaskedConstant(RRRttypet issubclassR(tarraysRtrclsR)tarrclstcls((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pytget_masked_subclasss     cC`sSy |j}Wn,tk r;tj|dtd|}nX|sO|jtS|S(sE 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=999999) >>> ma.getdata(a) array([[1, 2], [3, 4]]) Equivalently use the ``MaskedArray`` `data` attribute. >>> a.data array([[1, 2], [3, 4]]) R>tsubok(t_datatAttributeErrorRR RtviewR(R)R7tdata((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR[s+   cC`st|d|d|dt}tjtj|j}|jsI|S|j|O_|dkrp|j }n||j|<|S(s 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.00000000e+00, -1.00000000e+00, 1.00000000e+20, 1.00000000e+20]) >>> x.data array([ 1., -1., NaN, Inf]) R>tmaskR7N( R}tTrueRRutisfiniteR8R"t_maskRR#(R)R<R>R#tinvalid((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRRs1    t_DomainCheckIntervalcB`s eZdZdZdZRS(s~ Define a valid interval, so that : ``domain_check_interval(a,b)(x) == True`` where ``x < a`` or ``x > b``. cC`s2||kr||}}n||_||_dS(s9domain_check_interval(a,b)(x) = true where x < a or y > bN(R)R(tselfR)R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt__init__"s  c C`sKtjdd3tjtj||jtj||jSWdQXdS(sExecute the call behavior.R@tignoreN(RterrstatetumathRvR^RRmR)(RBtx((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt__call__)s(RRRRCRH(((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRAs t _DomainTancB`s eZdZdZdZRS(s Define a valid interval for the `tan` function, so that: ``domain_tan(eps) = True`` where ``abs(cos(x)) < eps`` cC`s ||_dS(s/domain_tan(eps) = true where abs(cos(x)) < eps)N(teps(RBRJ((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRC:scC`sBtjdd*tjtjtj||jSWdQXdS(sExecutes the call behavior.R@RDN(RRERFRmRR@RJ(RBRG((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRH>s(RRRRCRH(((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRI2s t_DomainSafeDividecB`s#eZdZddZdZRS(s- Define a domain for safe division. cC`s ||_dS(N(t tolerance(RBRL((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRCJscC`s|jdkr'tjtj|_ntj|tj|}}tjdd(tj ||jtj |kSWdQXdS(NR@RD( RLRRtfinfotfloatttinyR1RERFR(RBR)R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRHMs N(RRRRRCRH(((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRKDs t_DomainGreatercB`s eZdZdZdZRS(s4 DomainGreater(v)(x) is True where x <= v. cC`s ||_dS(s'DomainGreater(v)(x) = true where x <= vN(tcritical_value(RBRQ((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRC_scC`s0tjddtj||jSWdQXdS(sExecutes the call behavior.R@RDN(RRERFRnRQ(RBRG((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRHcs(RRRRCRH(((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRPYs t_DomainGreaterEqualcB`s eZdZdZdZRS(s8 DomainGreaterEqual(v)(x) is True where x < v. cC`s ||_dS(s+DomainGreaterEqual(v)(x) = true where x < vN(RQ(RBRQ((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRCoscC`s0tjddtj||jSWdQXdS(sExecutes the call behavior.R@RDN(RRERFRmRQ(RBRG((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRHss(RRRRCRH(((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRRis t _MaskedUFunccB`seZdZdZRS(cC`s%||_|j|_|j|_dS(N(RRR(RBtufunc((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRCzs  cC`sdj|jS(NsMasked version of {}(R R(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt__str__s(RRRCRU(((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRSys t_MaskedUnaryOperationcB`s&eZdZdddZdZRS(s 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. icC`s@tt|j|||_||_|t|<|t|R\RR|RtcopytoRR:R6R?t _update_from(RBR)targstkwargstdR*Rt masked_result((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRHs.       N(RRRRRCRH(((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRVst_MaskedBinaryOperationcB`sJeZdZdddZdZdddZdZddZRS(sC 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. icC`sFtt|j|||_||_dt|<||ft|R((i(R6R\RQReRRRRxRRRRFRtR|R:R?( RBttargettaxisRttclassRttttrtmrt masked_tr((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs(     $  c C`st|t|}}|jj||}t|}t|}|tkrg|tkrgt}n-t|}t|}tjj||}|j r|rt S|tk rt j ||d|n|j s|S|j t||} || _| S(sO Return the function applied to the outer product of a and b. R(R[RRR\RR]RFRvRR|RR]RR:R6R?( RBR)RRkRlRaRmRnRtmasked_d((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR;s$        cC`sFt|}t||j}|jj||}|j|}|S(sSAccumulate `target` along `axis` after filling with y fill value. (R6RQReRt accumulateR:(RBRoRpRqRrR*Rb((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRwTs  N( RRRRCRHRRRRw(((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRcs  / t_DomainedBinaryOperationcB`s&eZdZdddZdZRS(sH 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. icC`sOtt|j|||_||_||_|t|<||ft|R\RZRRRR|R]Rtcan_castRRjR:R6R?RRR^( RBR)RR_R`RkRlR*RRYt masked_daRb((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRHs6    (RRRRCRH(((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRxas gg?gz8ggV瞯>> import numpy.ma as ma >>> dtype = np.dtype({'names':['foo', 'bar'], 'formats':[np.float32, int]}) >>> dtype dtype([('foo', '>> ma.make_mask_descr(dtype) dtype([('foo', '|b1'), ('bar', '|b1')]) >>> ma.make_mask_descr(np.float32) dtype('bool') (RR(R$((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRy.scC`st|dtS(s 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=999999) >>> 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 R?(tgetattrR(R)((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR\Os:cC`sCt|}|tkr?ttj|t|dd}n|S(sk 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=999999) >>> 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(R\RRzRRRR(RR<((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR]s1  'cC`s-y|jjtkSWntk r(tSXdS(s  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 -------- 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=999999) >>> 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', '|b1'), ('pithon', '|b1')]) >>> ma.is_mask(m) False N(RR0RR9R(R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRis> cC`s&|jj r|j rtS|SdS(s- Shrink a mask to nomask if possible N(RRR"R(R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt _shrink_mask scC`s|tkrtSt|}t|tr\|jjr\|tjkr\tj|j d|Stj t |t d|d|dt }|rt |}n|S(s 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 interepreted 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':[int, int]}) >>> 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')]) RR>R7(RRyRRRRRRRRR RQR=R(RR>tshrinkRR*((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRxsG  **cC`sC|dkr$tj|dt}ntj|dt|}|S(s! 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, int]}) >>> dtype dtype([('foo', '>> ma.make_mask_none((3,), dtype=dtype) array([(False, False), (False, False), (False, False)], dtype=[('foo', '|b1'), ('bar', '|b1')]) RN(RRRRRy(tnewshapeRR*((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRzms+ c`safd|tks'|tkrUt|dt}t|d|d|d|S|tksm|tkrt|dt}t|d|d|d|S||krt|r|St|ddt|dd}}||krtd||fn|jr?t j t j ||j |}||||Stt j||d|d|S(s 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]) c`sm|jj}xZ|D]R}||}|jjrJ|||||qtj|||||qWdS(N(RRRFRv(tm1tm2tnewmaskRRtcurrent1(t_recursive_mask_or(s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs    RR>RsIncompatible dtypes '%s'<>'%s'N(RRRRRxRiRRRRRLt broadcastRRFRv(RRR>RRtdtype1tdtype2R((Rs,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR{s"% %  !c`s_d}fdtj|}||}tjg|D] }|^qFdtS(s 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]) >>> flatten_mask(mask) array([False, False, True]) >>> mask = np.array([(0, 0), (0, 1)], dtype=[('a', bool), ('b', bool)]) >>> 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) >>> flatten_mask(mask) array([False, False, False, False, False, True]) cS`s;|jj}|r3g|D]}t||^qS|SdS(sCFlatten the mask and returns a (maybe nested) sequence of booleans.N(RRRS(R<tmnamesR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt _flatmasks !c3`seyHxA|D]9}t|dr>x!|D] }|Vq,Wq |Vq WWntk r`|VnXdS(s.Generates a flattened version of the sequence.t__iter__N(RR(tsequencetelementR(t _flatsequence(s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR s    R(RR1R tbool(R<Rt flattenedR%((Rs,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRSs  cC`sE|tjkrin i|d6}|tk rA|jd||StS(s:Check whether there are masked values along the given axistkeepdimsRp(RR RR(R<RpRR`((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt_check_mask_axiss" cC`st|dt}tj|d|dt}|j|j}}|rk||krktd||fnt|drt||j }t |}nt }|j |}t ||_|S(st 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) Effect of the `copy` argument. >>> 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) RR>R7sFInconsistent shape between the condition and the input (got %s and %s)R?(RxRRR R=Rt IndexErrorRR{R?R0RR:RR<(t conditionR)R>tcondtcshapetashapeR5R*((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR&sccC`stt|||d|S(s 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>(RR^(RGtvalueR>((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRscC`stt|||d|S(s Mask an array where greater than or equal to a given value. This function is a shortcut to ``masked_where``, with `condition` = (x >= value). See Also -------- masked_where : Mask where a condition is met. Examples -------- >>> import numpy.ma as ma >>> a = np.arange(4) >>> a array([0, 1, 2, 3]) >>> ma.masked_greater_equal(a, 2) masked_array(data = [0 1 -- --], mask = [False False True True], fill_value=999999) R>(RR_(RGRR>((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRscC`stt|||d|S(s 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>(RRm(RGRR>((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRscC`stt|||d|S(s 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>(RRn(RGRR>((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRscC`stt|||d|S(s 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>(RR(RGRR>((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRscC`s+tt|||d|}||_|S(sa Mask an array where equal to a given value. This function is a shortcut to ``masked_where``, with `condition` = (x == 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=999999) R>(RRNR#(RGRR>toutput((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR~s cC`sQ||kr||}}nt|}||k||k@}t||d|S(sw 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>(RQR(RGtv1tv2R>txfR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR;s !  cC`sQ||kr||}}nt|}||k||kB}t||d|S(st 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>(RQR(RGRRR>RR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRcs !  cC`st|r-tj|j|}|j}n!tjtj||}t}t|t |d|}t |d|d|d|S(s 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') >>> print(eat) [-- ham] >>> # plain ol` ham is boring >>> fresh_food = np.array(['cheese', 'ham', 'pineapple'], dtype=object) >>> eat = ma.masked_object(fresh_food, 'green_eggs') >>> print(eat) [cheese ham pineapple] Note that `mask` is set to ``nomask`` if possible. >>> eat masked_array(data = [cheese ham pineapple], mask = False, fill_value=?) RR<R>R#( RhRFRNR8R?RR1RR{RxR}(RGRR>RRR<((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs3  gh㈵>g:0yE>c C`st||}tj|jtjrHtj||d|d|}ntj||}t|d|d|d|}|r|j n|S(s 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, 1.5) masked_array(data = [ 1. 1.1 2. 1.1 3. ], mask = False, fill_value=1.5) For integers, the fill value will be different in general to the result of ``masked_equal``. >>> x = np.arange(5) >>> x array([0, 1, 2, 3, 4]) >>> ma.masked_values(x, 2) masked_array(data = [0 1 -- 3 4], mask = [False False True False False], fill_value=2) >>> ma.masked_equal(x, 2) masked_array(data = [0 1 -- 3 4], mask = [False False True False False], fill_value=999999) tatoltrtolR<R>R#( RQRt issubdtypeRtfloatingtiscloseRFRNR}t shrink_mask( RGRRRR>RtxnewR<tret((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRsE! cC`stj|d|dt}t|dd}|dk rwtjt|}|tk rh||O}nt|}ntj|}t }|j |}||_ |S(s Mask an array where invalid values occur (NaNs or infs). This function is a shortcut to ``masked_where``, with `condition` = ~(np.isfinite(a)). Any pre-existing mask is conserved. Only applies to arrays with a dtype where NaNs or infs make sense (i.e. floating point types), but accepts any array_like object. See Also -------- masked_where : Mask where a condition is met. Examples -------- >>> import numpy.ma as ma >>> a = np.arange(5, dtype=float) >>> a[2] = np.NaN >>> a[3] = np.PINF >>> a array([ 0., 1., NaN, Inf, 4.]) >>> ma.masked_invalid(a) masked_array(data = [0.0 1.0 -- -- 4.0], mask = [False False True True False], fill_value=1e+20) R>R7R?N( RR R=RRR>R[RR0RR:R?(R)R>R<RR5R*((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR s    t_MaskedPrintOptioncB`sMeZdZdZdZdZdZddZdZeZ RS(sN Handle the string used to represent missing data in a masked array. cC`s||_t|_dS(s9 Create the masked_print_option object. N(t_displayR=t_enabled(RBtdisplay((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRCM s cC`s|jS(sA Display the string to print for masked values. (R(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRU scC`s ||_dS(s= Set the string to print for masked values. N(R(RBR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt set_display\ scC`s|jS(s; Is the use of the display value enabled? (R(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pytenabledc sicC`s ||_dS(s7 Set the enabling shrink to `shrink`. N(R(RBR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pytenablej scC`s t|jS(N(R R(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRUq s( RRRRCRRRRRUt__repr__(((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRG s      s--cC`sd|jj}|rJxK|D]*}||}||}t|||qWntj||d|dS(sg Puts printoptions in result where mask is True. Private function allowing for recursion RN(RRt_recursive_printoptionRR](R*R<tprintoptRRtcurdatatcurmask((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRz s    tlong_stds masked_%(name)s(data = %(data)s, %(nlen)s mask = %(mask)s, %(nlen)s fill_value = %(fill)s) tlong_flxs masked_%(name)s(data = %(data)s, %(nlen)s mask = %(mask)s, %(nlen)s fill_value = %(fill)s, %(nlen)s dtype = %(dtype)s) t short_stds masked_%(name)s(data = %(data)s, %(nlen)s mask = %(mask)s, %(nlen)s fill_value = %(fill)s) t short_flxs masked_%(name)s(data = %(data)s, %(nlen)s mask = %(mask)s, %(nlen)s fill_value = %(fill)s, %(nlen)s dtype = %(dtype)s) cC`sp|jj}x]|D]U}||}|jjrJt|||||qtj|||d||qWdS(s2 Recursively fill `a` with `fill_value`. RN(RRt_recursive_filledRR](R)R<R#RRtcurrent((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR s     c`sCfdtj|}|j}|j}t|trtjg|jD]}t|j ^qR}|j t}tjgt |D]}t|j ^q|_ n4tjg|D]}t|j ^q}t |dkr?t|j}||d>> ndtype = [('a', int), ('b', float)] >>> a = np.array([(1, 1), (2, 2)], dtype=ndtype) >>> flatten_structured_array(a) array([[1., 1.], [2., 2.]]) c3`sNxGt|D]9}t|drAx!|D] }|Vq/Wq |Vq WdS(s; Flattens a compound of nested iterables. RN(titerR(titerabletelmR(tflatten_sequence(s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR s  ii(RR0RRRRR R8RRR:R]R?RR~(R)tinishapeRatoutR((Rs,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRT s   7 74 c`s^fd}ttdp3ttd}|dk rQ|j|_n|_|S(s 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. c`st|j||}|jt|}|j||j}s\|j|n*|tk rt||||_n|S(N(RR8R:R0R^R?t __setmask__R(RBR_tparamsR*R<(tfuncnametonmask(s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pytwrapped_method s   N(RRRRRR(RRRtmethdoc((RRs,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt _arraymethod s  $  tMaskedIteratorcB`sAeZdZdZdZdZdZdZeZRS(s 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) cC`sF||_|jj|_|jtkr3d|_n|jj|_dS(N(RmR8tflattdataiterR?RRtmaskiter(RBRm((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRCQ s   cC`s|S(N((RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRZ scC`s|jj|jt|j}|jdk r|jj|}t|trl|j |_ ||_ qt|t j rt |d|d|jjS|rtSn|S(NR<thardmask(Rt __getitem__R:R0RmRRRRRR?RRRt _hardmaskR|(RBtindxR*R?((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR] s$  cC`s<t||j|<|jdk r8t||j|>> x = np.ma.array([3, 2], mask=[0, 1]) >>> fl = x.flat >>> fl.next() 3 >>> fl.next() masked_array(data = --, mask = True, fill_value = 1e+20) >>> fl.next() Traceback (most recent call last): File "", line 1, in File "/home/ralf/python/numpy/numpy/ma/core.py", line 2243, in next d = self.dataiter.next() StopIteration R<RN( tnextRRRRRRRRmRR|(RBRaR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt__next__q s( RRRRCRRRRR(((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR! s.    c B`seZdZdZeZeZeZ dZ dZ dedee dde de dd ZdZdZddZdddd Zejje_d Zd Zed Zejd ZedZejdZedZeZdZedededdZdZdZedeZdZ dZ!eddddZ"dZ#eddddZ$dZ%edd dd!Z&d"Z'ede'Z(ede'Z)d#Z*d$Z+ede*de+dd%Z,d&Z-dd'Z.ede-de.dd(Z/dd)Z0d*Z1ddd+Z2d,Z3d-Z4e5j6j7d.krd/Z8nd0Z9d1Z:d2Z;d3Z<d4Z=d5Z>d6Z?d7Z@d8ZAd9ZBd:ZCd;ZDd<ZEd=ZFd>ZGd?ZHd@ZIdAZJdBZKdCZLdDZMdEZNdFZOdGZPdHZQdIZRdJZSdKZTdLZUedeUddMZVdNZWedeWddOZXdeYjZdPZ[dQdRZ\dSZ]e edTZ^dUdVZ_dWZ`dXZaddeYjZdYZbddeYjZdZZcd[Zdddd\ddd]Zeejejee_ded^ZfdddeYjZd_Zgdddd`ZhdddeYjZdaZieiZjddddbZkdddeYjZdcZlddddZmddddeYjZdeZneYjnjen_ddddeYjZdfZodddgZpeYjZdhde ddiZqddddjZrddddkZsdldhde ddmZtdddeYjZdnZuddoZvdddeYjZdpZwdddedqZxdrZydsZzdddUdtZ{e|dudveZ}e|dwZ~e|dxZe|dyZe|dzZe|d{Ze|d|Zedd}Ze|d~ZddZddQdZddQdZdddZdZeZdZdZdZddZRS(s 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. iidiic  `stj|d|d|d| dtd|} t|dt| }t|tro|j| jkrot}nt||r|rt|t rt j | t|} nt j | |} t |drt|t  r|j | _ t}nt | j}|tkr#|sF| r(t| _ q tj| jd|| _ qt|ttfry2tjg|D]}t|^qkd|}Wntk rt}nX|tkr |jr || _ t| _q q| | _|r| j j| _ t|tk r |j|j _q qn|tkrV|tkrVtj| jd|}n|tkr|tkrtj| jd|}nnytj|d|d|}WnLtk rtjg|D]}t|gt|^qd|}nX|j| jkr| j|j}}|dkr@tj|| j}nD||krdtj || j}n d d }t!|||ft}n| j tkr|| _ | | _nk|s|| _ | | _nO| jj"rfd | j |ntj#|| j | _ t| _|dkr>t|d d}n|dk rbt%|| j| _&n| dkrt|d t| _'n | | _'|| _(| S(s Create a new masked array from scratch. Notes ----- A masked array can also be created by taking a .view(MaskedArray). RR>torderR7tndmint _baseclassR?is/Mask and data not compatible: data size is %i, smask size is %i.c`sVxO|jjD]A}||||}}|jjrD||q ||O}q WdS(s'do a|=b on each field of a, recursivelyN(RR(R)RRtaftbf(t _recursive_or(s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR: s  t _fill_valueRN()RR R=RR0RRRR/RR:RR?RyRRRRR~R]RRR"Rt _sharedmaskR>R\RRRRRRRRRvRR(RRR(R5R;R<RR>R7RR#t keep_maskt hard_maskRRtoptionsR8RRtmdtypeRtndtnmtmsg((Rs,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt__new__ s ! %    %      2                cC`st|trt|}nt}i}|jt|di|jt|dit|ts|jt|dintdt|dd dt|dtdt|dtdt|dtdt|d|d|d|}|j j||j j|d S( s9 Copies some attributes of obj to self. t_optinfot _basedictt__dict__RRRt_isfieldRN( RRR0tupdateRRR.RRR(RBRRRt_dict((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR^V s$ cC`s|j|t|tr|jjr7t|}n t|}|tk r|jdd|jddkr|j|jkr|j}nt |j}|j j rd}n|j j rd}nd}|j ||}q|j}nt}||_|jtk rYy|j|j_WqYtk r?t|_qYttfk rUqYXn|jjr|jdkrtd|j|_qndS(s. Finalizes the masked array. R;itCtFtKN(R^RRRRR]R\Rt__array_interface__Rytflagst c_contiguoust f_contiguoustastypeR:R?RRRR9RRR((RBRR?t _mask_dtypeR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt__array_finalize__p s<            c C`s||kr|}n"|jt|}|j||dk r|jj|_|\}}}||j }ttg|D]}t |^q~} t j |d} | dk r{t j ddddt| |t} WdQX| jr{yt|d} Wn4tk r&t|} ntk r?|j} nXt j|| d| | tkrk| } qx| | B} q{n||k r|jdkr| rtS| |_t|_n|S(sr Special hook for ufuncs. Wraps the numpy array and sets the mask according to context. RIRDR@NiR((R:R0R^RR?R>tninRR{R]RZRRRERQR=R"R[RR R#R]RRR|RR( RBRtcontextR*tfuncR_tout_it input_argstargRRYRaR#((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt__array_wrap__ s:     (        !  cC`s?|dkr?|dkr*tj|}qtj||}n|dkry@t|trxtj||}d}ntj||}Wqtk rtj||}qXntj|||}t|tk r|jj|_nt|dddk r;|dkr/|dkr#q8d|_ q;||_ n|S(s 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. 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. RN( RRR:R1RR\RR?RRR#(RBRR0R#R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR: s,0         cC`s"|j|}|j}d}d}|tk rM||}||}n=t}||j|}|d kr|t||}n|rt|tjrt|d|d|j S|j j tj kr t|tj r |tk r |rt|dtS|Sq|rtS|Sn|jt |}|j|t|tr|jd k r|j||_|jjdkr|j|jjdkjstjdjd|d|jdd d n|jjd|_qnt|_n|tk rt||j|_t|_n|S( si x.__getitem__(y) <==> x[y] Return the item described by i, as a masked array. cS`st|tj S(N(RRR(R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt _is_scalard scS`sdt|tjstS|jjtjkrD|j|jk r`tSnt|jtjkr`tSdS(s Return whether `elem` is a scalar result of indexing `arr`, or None if undecidable without promoting nomask to a full mask N( RRRR=RR0tobject_RRR(Rtelem((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt_scalar_heuristicg sR<RisUpon accessing multidimensional field {indx:s}, need to keep dimensionality of fill_value at 0. Discarding heterogeneous fill_value and setting all to {fv!s}.RtfvRiN(R;R?RRR]RRRRRRR0RRR|RR=R:R^RRRRRRRR RRRR(RBRtdoutR?RRtmouttscalar_expected((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRV sT               c C`s|tkrtdn|j}|j}t|tr|||<|tkrqt|j|j |_}nt ||| x[i]=y Set item described by index. If value is masked, masks those locations. s Cannot alter the masked element.NR8Rs,Flexible 'hard' masks are not yet supported.R>iR((R|RR8R?RRRRzRRR\RRRR=RRRRRRFRutNotImplementedErrorR{RRR]( RBRRR8R?t_dtypetnbfieldstdvaltmvalR'tmindxtdindx((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR s\                      cC`stt|jS(N(RWRR(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR scC`sttt|jj|||jtk r|jjt|t |_y|j |j_ Wqt t fk r{qXndS(N( RWRR0Rt__set__R?RR:RyRRR9R(RBR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR s"cC`stt|jS(N(RWRR(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR! scC`sJttt|jj||t|tk rF|j|j_ndS(N(RWRR0RR R\RR?(RBR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR% s"cC`s/|j}|j}|tkr't}n|tkr_|tkrCdSt|j|}|_n|jdkr|j r||O}qt |t t t jt jfr||dRR(RR?R|R=RRzRRRRRtintRNRRtnumberRR RRRRRRRR(RBR<R>tidtypet current_maskRRtn((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR- sF        !    %  2  !   cC`s|jS(s"Return the current mask. (R?(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt _get_maskt stfgettfsettdoctMaskcC`sA|jjt}|jjdkr(|Stjt|ddS(sn Return the mask of the records. A record is masked when all the fields are masked. RpiN( R?R:RRRRRRRT(RBR?((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt_get_recordmask~ scC`stddS(sn Return the mask of the records. A record is masked when all the fields are masked. s*Coming soon: setting the mask per records!N(R(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt_set_recordmask scC`s t|_|S(s Force the mask to hard. Whether the mask of a masked array is hard or soft is determined by its `hardmask` property. `harden_mask` sets `hardmask` to True. See Also -------- hardmask (R=R(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR` s cC`s t|_|S(s Force the mask to soft. Whether the mask of a masked array is hard or soft is determined by its `hardmask` property. `soften_mask` sets `hardmask` to False. See Also -------- hardmask (RR(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR s cC`s|jS(N(R(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt ssHardness of the maskcC`s+|jr'|jj|_t|_n|S(sS 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 (RR?R>R(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt unshare_mask s  cC`s|jS(N(R(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR ss%Share status of the mask (read-only).cC`st|j|_|S(s 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() >>> x.mask False (RR?(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR scC`s|jS(N(R(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR ss)Class of the underlying data (read-only).cC`stj||jS(sUReturn the current data, as a view of the original underlying data. (RR:R(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt _get_data scC`s t|S(sReturn a flat iterator.(R(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt _get_flat scC`s|j}||(dS(s)Set a flattened version of self to value.N(R(RBRty((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt _set_flat s sFlat version of the array.cC`sK|jdkr'td|j|_nt|jtrD|jdS|jS(s Return the filling value of the masked array. Returns ------- fill_value : scalar The filling value. Examples -------- >>> for dt in [np.int32, np.int64, np.float64, np.complex128]: ... np.ma.array([0, 1], dtype=dt).get_fill_value() ... 999999 999999 1e+20 (1e+20+0j) >>> x = np.ma.array([0, 1.], fill_value=-np.inf) >>> x.get_fill_value() -inf N((RRR(RRR(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR+ s  cC`sAt||j}|j}|dkr3||_n ||d>> x = np.ma.array([0, 1.], fill_value=-np.inf) >>> x.fill_value -inf >>> x.set_fill_value(np.pi) >>> x.fill_value 3.1415926535897931 Reset to default: >>> x.set_fill_value() >>> x.fill_value 1e+20 N((R(RRR(RBRRoR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR!s    sFilling value.cC`su|j}|tkr|jS|dkr4|j}nt||j}|tkr_tj |S|jj r|jj d}t ||j|n|j s|jS|jj d}ytj||d|Wnttfk r$t|dt}|jt}tj|||f}nMtk rp|jjrCqq|rdtj|d|j}qq|j}nX|S(s 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 : scalar, optional The value to use for invalid entries (None by default). If None, 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]) >>> 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', 'RR"R]RR9tnarrayR RR6RRR (RBR#RR*Ra((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRQKs6)           cC`sLtj|j}|jtk rH|jtjtj|j}n|S(s Return all the non-masked data as a 1-D array. Returns ------- data : ndarray A new `ndarray` holding the non-masked data is returned. Notes ----- The result is **not** a MaskedArray! Examples -------- >>> x = np.ma.array(np.arange(5), mask=[0]*2 + [1]*3) >>> x.compressed() array([0, 1]) >>> type(x.compressed()) (RRR8R?RR9RRu(RBR;((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR:s'cC`s|j|j}}tj|dtdt}|j|d|d|jt|}|j||t k r|j|d||_n|S(sJ Return `a` where condition is ``True``. If condition is a `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:`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) >>> print(x) [[1 -- 3] [-- 5 --] [7 -- 9]] >>> 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>R7RpR( R8R?RR RR9R:R0R^R(RBRRpRR8R?t_new((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR9s8*  c C`s_tjrI|j}|tkr-|j}q[|j}|jdkrN|jn|j}xt|jD]}|j ||krg|d}t j ||| fd|}t j |d|dfd|}t j ||| fd|}t j |d|dfd|}qgqgWt |jd}|j|}t||tn|j|j}|S(sq Replace masked values with masked_print_option, casting all innermost dtypes to object. iiRpiR(RRR?RR8Rt _print_widtht_print_width_1dtrangeRRRR;RRRRRQR#( RBR<tresR;t print_widthRptindRtrdtype((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt_insert_masked_prints&       #*cC`st|jS(N(R R)(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRUsicC`st|jS(N(RR)(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt __unicode__sc `s|jtjkrd}n |jj}tjddkr|jdk}td|ddt|dt|d t|j d t|j d t|j }t |j j }d j|rd nd|rdnd}t||Sdj|}tjjj|j  p2tj|jp2|jdk}dd dg}|rZ|jd ntjd|jd D} d| ri||d} tjt||dt| } d| | GsiiRc`si|]}d|qS(R-((Rtk(t min_indent(s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pys Vs s t separators, tprefixsdata=tsuffixt,smask=s, c3`s,|]"}dj|||VqdS(s{}{}={}N(R (RR1(tindentstreprs(s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pys kst)(RRRRtget_printoptionsRR.RR R?R#RRRR t_legacy_print_templatestcoret arrayprinttdtype_is_impliedRR<RR#tbuiltinsRRt array2stringR)treprtdtype_short_reprR( RBRtis_longt parameterst is_structuredtkeyR4t dtype_neededtkeyst is_one_rowR1RR*((R7R2R8s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRsj     *       cC`sdt|t|rtSt|dt}|tkrVt|dd}|j|kS|dkSdS(Nt__array_ufunc__t__array_priority__i(RR0RRRKR(RBtothert array_ufunctother_priority((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt_delegate_binopps  c C`sot|}|j}t||dt}t|}|jjrtj||j }tj ||dt}||_ |j |} |tj d|jk}n |j} || |} t| tjtfr|rtS| S|tk r@tj||||| } |j | j kr@tj || j j}q@n| jt|} | j||| _ | S(sCompare self with other using operator.eq or operator.ne. When either of the elements is masked, the result is masked as well, but the underlying boolean data are still set, with self and other considered equal if both are masked, and unequal otherwise. For structured arrays, all fields are combined, with masked values ignored. The result is masked if all fields were masked, with self and other considered equal only if both were fully masked. R>R7((R\R<R{R=R[RRRRRt broadcast_toR?RQRR;RRRR|RRR>R:R0R^( RBRLtcomparetomasktsmaskR<todatatbroadcast_shapet sbroadcasttsdatatcheck((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt _comparison~s,       !  cC`s|j|tjS(sCheck whether other equals self elementwise. When either of the elements is masked, the result is masked as well, but the underlying boolean data are still set, with self and other considered equal if both are masked, and unequal otherwise. For structured arrays, all fields are combined, with masked values ignored. The result is masked if all fields were masked, with self and other considered equal only if both were fully masked. (RYtoperatorteq(RBRL((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt__eq__s cC`s|j|tjS(sCheck whether other does not equal self elementwise. When either of the elements is masked, the result is masked as well, but the underlying boolean data are still set, with self and other considered equal if both are masked, and unequal otherwise. For structured arrays, all fields are combined, with masked values ignored. The result is masked if all fields were masked, with self and other considered equal only if both were fully masked. (RYRZtne(RBRL((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt__ne__s cC`s |j|rtSt||S(sD Add self to other, and return a new masked array. (ROtNotImplementedR(RBRL((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt__add__scC`s t||S(sD Add other to self, and return a new masked array. (R(RBRL((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt__radd__scC`s |j|rtSt||S(sK Subtract other from self, and return a new masked array. (ROR_R(RBRL((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt__sub__scC`s t||S(sK Subtract self from other, and return a new masked array. (R(RBRL((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt__rsub__scC`s |j|rtSt||S(s6Multiply self by other, and return a new masked array.(ROR_R(RBRL((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt__mul__scC`s t||S(sI Multiply other by self, and return a new masked array. (R(RBRL((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt__rmul__scC`s |j|rtSt||S(sI Divide other into self, and return a new masked array. (ROR_RI(RBRL((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt__div__scC`s |j|rtSt||S(sI Divide other into self, and return a new masked array. (ROR_R(RBRL((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt __truediv__scC`s t||S(sI Divide self into other, and return a new masked array. (R(RBRL((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt __rtruediv__scC`s |j|rtSt||S(sI Divide other into self, and return a new masked array. (ROR_RV(RBRL((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt __floordiv__scC`s t||S(sI Divide self into other, and return a new masked array. (RV(RBRL((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt __rfloordiv__!scC`s |j|rtSt||S(sQ Raise self to the power other, masking the potential NaNs/Infs (ROR_R(RBRL((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt__pow__(scC`s t||S(sQ Raise other to the power self, masking the potential NaNs/Infs (R(RBRL((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt__rpow__1scC`st|}|jtkr`|tk r~|jr~t|j|j|_|j|7_q~n|tk r~|j|7_n|jjt j |j|jj dt ||S(s. Add other to self in-place. i( R\R?RR"RzRRR8t__iadd__RRR0R[(RBRLR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRm8s  $cC`st|}|jtkr`|tk r~|jr~t|j|j|_|j|7_q~n|tk r~|j|7_n|jjt j |j|jj dt ||S(s5 Subtract other from self in-place. i( R\R?RR"RzRRR8t__isub__RRR0R[(RBRLR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRnIs  $cC`st|}|jtkr`|tk r~|jr~t|j|j|_|j|7_q~n|tk r~|j|7_n|jjt j |j|jj dt ||S(s3 Multiply self by other in-place. i( R\R?RR"RzRRR8t__imul__RRR0R[(RBRLR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRoYs  $cC`st|}tj|j|}t|}t||}|jrvttj \}}tj |||}n|j |O_ |jj tj |j |j jd||S(s1 Divide self by other in-place. i(R[RKRHR8R\R{R"R[RRIRR?t__idiv__RR0(RBRLt other_datatdom_maskt other_masktnew_maskR%R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRpis   $ cC`st|}tj|j|}t|}t||}|jrvttj \}}tj |||}n|j |O_ |jj tj |j |j jd||S(s7 Floor divide self by other in-place. i(R[RKRHR8R\R{R"R[RRVRR?t __ifloordiv__RR0(RBRLRqRrRsRtR%R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRu{s   $ cC`st|}tj|j|}t|}t||}|jrvttj \}}tj |||}n|j |O_ |jj tj |j |j jd||S(s6 True divide self by other in-place. i(R[RKRHR8R\R{R"R[RRRR?t __itruediv__RR0(RBRLRqRrRsRtR%R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRvs   $ c C`st|}t|}tjdddd3|jjtj|j|jj d|WdQXtj tj |j}|j r|jt k r|j|O_n ||_tj|j|jd|nt||}t|j||_|S(s; Raise self to the power other, in place. RIRDR@iNR(R[R\RRER8t__ipow__RR?RR0RuR>R"RR]R#R{(RBRLRqRsR@Rt((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRws  $  cC`sQ|jdkrtdn#|jrAtjdddtjSt|jS(s$ Convert to float. is7Only length-1 arrays can be converted to Python scalarss,Warning: converting a masked element to nan.Ri( RRR?RRRtnanRNR(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt __float__s  cC`sF|jdkrtdn|jr6tdnt|jS(s" Convert to int. is7Only length-1 arrays can be converted to Python scalarss.Cannot convert masked element to a Python int.(RRR?RRR(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt__int__s  cC`sF|jdkrtdn|jr6tdnt|jS(s" Convert to long. is7Only length-1 arrays can be converted to Python scalarss/Cannot convert masked element to a Python long.(RRR?RRR(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt__long__s  cC`s/|jjjt|}|j|j|S(s Return the imaginary part of the masked array. The returned array is a view on the imaginary part of the `MaskedArray` whose `get_imag` method is called. Parameters ---------- None Returns ------- result : MaskedArray The imaginary part of the masked array. See Also -------- get_real, real, imag Examples -------- >>> x = np.ma.array([1+1.j, -2j, 3.45+1.6j], mask=[False, True, False]) >>> x.get_imag() masked_array(data = [1.0 -- 1.6], mask = [False True False], fill_value = 1e+20) (R8timagR:R0RR?(RBR*((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pytget_imagssImaginary part.cC`s/|jjjt|}|j|j|S(s Return the real part of the masked array. The returned array is a view on the real part of the `MaskedArray` whose `get_real` method is called. Parameters ---------- None Returns ------- result : MaskedArray The real part of the masked array. See Also -------- get_imag, real, imag Examples -------- >>> x = np.ma.array([1+1.j, -2j, 3.45+1.6j], mask=[False, True, False]) >>> x.get_real() masked_array(data = [1.0 -- 3.45], mask = [False True False], fill_value = 1e+20) (R8trealR:R0RR?(RBR*((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pytget_realss Real partc C`s|tjkrin i|d6}|j}t|jtjr|tkrjtj|jdtj }n|j t |j}n|tkr|jdkr|d krtj d|d|jndS|d kr|jdtrtj|jdtjd|jS|jSt||j}d}x|D]}||j|9}q4W|jdtrt|j}xO|D]} d|| >> 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]) RRiRpRiR(N(Ni(RR R?RR;tmatrixRRRRR:R0Rt AxisErrorRRRR RtintpRR~t enumerateRR|R( RBRpRR`Rtaxestitemstaxtout_dimsR)RRa((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRBs:9"     "   RcC`sztj|jd|jt|}|j||jtk rmtj|jd|j|j |_n t|_|S(s 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. 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) >>> print(x) [[1 -- 3] [-- 5 --] [7 -- 9]] >>> print(x.ravel()) [1 -- 3 -- 5 -- 7 -- 9] R( RRR8R:R0R^R?RRR(RBRtr((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs %' * cO`s~|jd|jdd|jj||jt|}|j||j}|tk rz|j|||_n|S(s 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]) >>> print(x) [[-- 2] [3 --]] >>> x = x.reshape((4,1)) >>> print(x) [[--] [2] [3] [--]] RR( RRR8RR:R0R^R?R(RBRR`R*R<((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs0$   cC`sd}t|dS(sv .. 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. soA masked array does not own its data and therefore cannot be resized. Use the numpy.ma.resize function instead.N(R(RBRtrefcheckRterrmsg((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs traisecC`s+|jrx|jtk rx|j|}t|dt}t|dtdt}|j|j||}||}n|jj ||d||jtkrt |tkrdSt |}t |tkr|j |td|n|j ||jd|t |dtdt}||_dS(s 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) >>> print(x) [[1 -- 3] [-- 5 --] [7 -- 9]] >>> x.put([0,4,8],[10,20,30]) >>> print(x) [[10 -- 3] [-- 20 --] [7 -- 30]] >>> x.put(4,999) >>> print(x) [[10 -- 3] [-- 999 --] [7 -- 30]] R>R7tmodeNR( RR?RR RR=RRR8RR\R]Rx(RBRdtvaluesRR<R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs".  !  cC`s>|jtkr%|jjttfS|jj|jjjfS(s 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) 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, 3083169284L) (R?RtctypesR;tid(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRc@scC`s |jdS(s 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 UPDATEIFCOPY : False t CONTIGUOUS(R(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt iscontiguousZscC`s|tjkrin i|d6}t|j||}|dkr|jtjd||jt |}|j r|j |n |rt S|S|jtjd|d||t |tr|j s|r|j |qn|S(s 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 -------- 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 RRpRN(RR RR?RRQR=RR:R0RRR|RR(RBRpRRR`R<Ra((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRvs" - "cC`s|tjkrin i|d6}t|j||}|dkr|jtjd||jt |}|j r|j |n|rt }n|S|jtjd|d||t |tr|j s|r|j |qn|S(sM 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 -------- ndarray.any : corresponding function for ndarrays numpy.any : equivalent function RRpRN(RR RR?RRQRR"R:R0RRR|RR(RBRpRRR`R<Ra((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR"s" -  "cC`st|jddtjS(s 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. 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=999999) >>> 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])) iR>(R RQRR(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRscic C`s|j}|tkrOtt|jd|d|d|d|}|j|S|jd|d|d|}|j|jdjddd|SdS( s8 (this docstring should be overwritten) toffsettaxis1taxis2RiRpiN( R?RRWRRRRGRQR( RBRRRRRRR*R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR!s   cC`st||d|d|S(s a.dot(b, out=None) Masked dot product of two arrays. Note that `out` and `strict` are located in different positions than in `ma.dot`. In order to maintain compatibility with the functional version, it is recommended that the optional arguments be treated as keyword only. At some point that may be mandatory. .. versionadded:: 1.10.0 Parameters ---------- b : masked_array_like Inputs array. out : masked_array, optional Output argument. This must have the exact kind that would be returned if it was not used. In particular, it must have the right type, must be C-contiguous, and its dtype must be the dtype that would be returned for `ma.dot(a,b)`. This is a performance feature. Therefore, if these conditions are not met, an exception is raised, instead of attempting to be flexible. strict : bool, optional Whether masked data are propagated (True) or set to 0 (False) for the computation. Default is False. Propagating the mask means that if a masked value appears in a row or column, the whole row or column is considered masked. .. versionadded:: 1.10.2 See Also -------- numpy.ma.dot : equivalent function Rtstrict(tdot(RBRRR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR0s%c C`s1|tjkrin i|d6}|j}t|||}|dkr|jdj|d||}t|dd} | r|jt |}|j |n|rt }n|S|jdj|d|d||}t |t r-t|} | tkr!t|j} |_n|| _n|S(s 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 -------- 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) >>> print(x) [[1 -- 3] [-- 5 --] [7 -- 9]] >>> print(x.sum()) 25 >>> print(x.sum(axis=1)) [4 5 16] >>> print(x.sum(axis=0)) [8 5 12] >>> print(type(x.sum(axis=0, dtype=np.int64)[0])) RiRRRN(RR R?RRRQRRR:R0RR|RRR\RRzRR( RBRpRRRR`R?RR*trndimtoutmask((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRWs&"  ! '   cC`s|jdjd|d|d|}|dk rYt|trU|j|jn|S|jt|}|j|j |S(sE 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:`MaskedArray` ! Arithmetic is modular when using integer types, and no error is raised on overflow. See Also -------- 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]) >>> print(marr.cumsum()) [0 1 3 -- -- -- 9 16 24 33] iRpRRN( RQRDRRRRR<R:R0R?(RBRpRRR*((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRDs' c C`s1|tjkrin i|d6}|j}t|||}|dkr|jdj|d||}t|dd} | r|jt |}|j |n|rt }n|S|jdj|d|d||}t |t r-t|} | tkr!t|j} |_n|| _n|S(s 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 -------- ndarray.prod : corresponding function for ndarrays numpy.prod : equivalent function RiRRiRN(RR R?RRRQRRR:R0RR|RRR\RRzRR( RBRpRRRR`R?RR*RR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs&"  ! '   cC`s|jdjd|d|d|}|dk rYt|trU|j|jn|S|jt|}|j|j|S(s 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 -------- ndarray.cumprod : corresponding function for ndarrays numpy.cumprod : equivalent function iRpRRN( RQRCRRRRR?R:R0(RBRpRRR*((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRCs' c C`s-|tjkrin i|d6}|jtkr\tt|jd|d||d}nb|jd|d||}|jd||}|j dkr|dkrt }n|d|}|dk r)||_ t |tr%t|} | tkrt|j } |_nt|| _ n|S|S( s 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 -------- 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 RRpRig?((N(RR R?RRWRRRRBRR|RRRR\Rz( RBRpRRRR`R*tdsumtcntR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs$"     cC`sE|j||}|tkr"|S|s0||S|t||SdS(s 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(RR|R(RBRpRR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR +s  c C`s"|tjkrin i|d6}|jtkrtt|jd|d|d|d||d }|d k rt|tr|j tn|S|S|j d|||}||j ||dt } t |rtj| d} n | | 9} t| j|||jt|} | jrct|jj|||dk| _| j|nt| rt} |d k rt|trd|_|j t n3|jjdkrd } t| n tj|_|Sn|d k r| |_t|tr|j | jn|S| S( so 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 -------- ndarray.var : corresponding function for ndarrays numpy.var : Equivalent function RRpRRtddofiitbius>Masked data information would be lost in one or more location.(N( RR R?RRWRRRRRRBRR=RRFRRIRR:R0RR{RR^R\R|RRRRRxR<( RBRpRRRRR`RRtdanomtdvarR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRSsF"$   * '      cC`s|tjkrin i|d6}|j|||||}|tk r|dk rutj|dd|dd|St|}n|S(s8 Returns the standard deviation of the array elements along given axis. Masked entries are ignored. Refer to `numpy.std` for full documentation. See Also -------- ndarray.std : corresponding function for ndarrays numpy.std : Equivalent function Rg?RRgRhN(RR RR|RRR(RBRpRRRRR`R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs"  cC`s|jjd|d|jt|}|jdkrU|j|_|j|n|jrgt}n|dkrw|St |t r|j |jn|S(s Return each element rounded to the given number of decimals. Refer to `numpy.around` for full documentation. See Also -------- ndarray.around : corresponding function for ndarrays numpy.around : equivalent function tdecimalsRiN( R8RR:R0RR?R^R|RRRR(RBRRR*((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs *    t quicksortcC`s|tjkrt|}n|dkrr|rctj|jtjrTtj}qot|}qrt |}n|j |}|j d|d|d|S(s 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 Sorting algorithm. 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 : {var}, optional Value used internally for the masked values. If ``fill_value`` is not None, it supersedes ``endwith``. Returns ------- index_array : ndarray, int Array of indices that sort `a` along the specified axis. In other words, ``a[index_array]`` yields a sorted `a`. See Also -------- MaskedArray.sort : Describes sorting algorithms used. lexsort : Indirect stable sort with multiple keys. 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]) RpRRN( RR RRRRRRxRRRQR.(RBRpRRtendwithR#RQ((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR.s@  cC`sF|dkrt|}n|j|jt}|j|d|S(s 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 : {var}, 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(arange(4), mask=[1,1,0,0]) >>> x.shape = (2,2) >>> print(x) [[-- --] [2 3]] >>> print(x.argmin(axis=0, fill_value=-1)) [0 0] >>> print(x.argmin(axis=0, fill_value=9)) [1 1] RN(RRRQR:RR-(RBRpR#RRa((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR-s$ cC`sI|dkrt|j}n|j|jt}|j|d|S(s 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 : {var}, 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]) RN(RRR8RQR:RR,(RBRpR#RRa((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR,=s ic C`s|jtkr2tj|d|d|d|dS|tkrBdS|jd|d|d|d|d|}tj||d||d>> a = ma.array([1, 2, 5, 4, 3],mask=[0, 1, 0, 1, 0]) >>> # Default >>> a.sort() >>> print(a) [1 3 5 -- --] >>> a = ma.array([1, 2, 5, 4, 3],mask=[0, 1, 0, 1, 0]) >>> # Put missing values in the front >>> a.sort(endwith=False) >>> print(a) [-- -- 1 3 5] >>> a = 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) >>> print(a) [1 -- -- 3 5] RpRRNR#R.(R?RRRR|R.Rttake_along_axis(RBRpRRRR#tsidx((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRbsA c C`s|tjkrin i|d6}|j}t|||}|dkrXt|}n|dkr|j|jd|d||jt |}|j r|j ||j rtj ||j d|qn|rt}n|S|j|jd|d||}t|trXt|} | tkrLt|j} |_n|| _n@|jjdkrd} t| ntj |tjd||S(si Return the minimum along a given axis. Parameters ---------- axis : {None, int}, optional Axis along which to operate. By default, ``axis`` is None and the flattened input is used. 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 : {var}, optional Value used to fill in the masked values. If None, use the output of `minimum_fill_value`. Returns ------- amin : array_like New array holding the result. If ``out`` was specified, ``out`` is returned. See Also -------- minimum_fill_value Returns the minimum filling value for a given datatype. RRpRRRs>Masked data information would be lost in one or more location.N(RR R?RRRRQRR:R0RRR]R#R|RRR\RRzRRRRRRx( RBRpRR#RR`R?RR*RR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs4"   !    $   cC`s&tjdtddtj||S(s Return the array minimum along the specified axis. .. deprecated:: 1.13.0 This function is identical to both: * ``self.min(keepdims=True, axis=axis).squeeze(axis=axis)`` * ``np.ma.minimum.reduce(self, axis=axis)`` Typically though, ``self.min(axis=axis)`` is sufficient. Parameters ---------- axis : int, optional The axis along which to find the minima. Default is None, in which case the minimum value in the whole array is returned. Returns ------- min : scalar or MaskedArray If `axis` is None, the result is a scalar. Otherwise, if `axis` is given and the array is at least 2-D, the result is a masked array with dimension one smaller than the array on which `mini` is called. Examples -------- >>> x = np.ma.array(np.arange(6), mask=[0 ,1, 0, 0, 0 ,1]).reshape(3, 2) >>> print(x) [[0 --] [2 3] [4 --]] >>> x.mini() 0 >>> x.mini(axis=0) masked_array(data = [0 3], mask = [False False], fill_value = 999999) >>> print(x.mini(axis=1)) [0 2 4] There is a small difference between `mini` and `min`: >>> x[:,1].mini(axis=0) masked_array(data = --, mask = True, fill_value = 999999) >>> x[:,1].min(axis=0) masked sL`mini` is deprecated; use the `min` method or `np.ma.minimum.reduce instead.Ri(RRtDeprecationWarningRR(RBRp((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pytminis4 c C`s|tjkrin i|d6}|j}t|||}|dkrXt|}n|dkr|j|jd|d||jt |}|j r|j ||j rtj ||j d|qn|rt}n|S|j|jd|d||}t|trXt|} | tkrLt|j} |_n|| _n@|jjdkrd} t| ntj |tjd||S(si Return the maximum along a given axis. Parameters ---------- axis : {None, int}, optional Axis along which to operate. By default, ``axis`` is None and the flattened input is used. 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 : {var}, optional Value used to fill in the masked values. If None, use the output of maximum_fill_value(). Returns ------- amax : array_like New array holding the result. If ``out`` was specified, ``out`` is returned. See Also -------- maximum_fill_value Returns the maximum filling value for a given datatype. RRpRRRs>Masked data information would be lost in one or more location.N(RR R?RRRRQRR:R0RRR]R#R|RRR\RRzRRRRRRx( RBRpRR#RR`R?RR*RR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR(s4"   !    $   c C`s|dkrP|jd|d|d|}||jd|d|d|8}|S|jd|d|d|d||_|jd|d|d|}tj||d|dd|S(s/ Return (maximum - minimum) along the given dimension (i.e. peak-to-peak value). 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 : {var}, optional Value used to fill in the masked values. Returns ------- ptp : ndarray. A new array holding the result, unless ``out`` was specified, in which case a reference to ``out`` is returned. RpR#RRRgRhN(RRRRRR(RBRpRR#RR*t min_value((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRgs     cO`s;tjdj|jjddtt|j||S(Ns6Warning: 'partition' will ignore the 'mask' of the {}.Ri(RRR t __class__RRWRt partition(RBR_R`((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs cO`s;tjdj|jjddtt|j||S(Ns9Warning: 'argpartition' will ignore the 'mask' of the {}.Ri(RRR RRRWRt argpartition(RBR_R`((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs c C`s|j|j}}t|}t|}|tk rI|jd}n|dkr|j|d|d|dj|}n"t j||d|d|d|t |t r|tkr|} n%|j|d|d|} | |O} |j | n|dS(s iRpR.RN(( R8R?R0R\RRQRRR:RRRR( RBRdRpRRR8R?R5t maskindicesR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs    +"   R7RR>RGtflattenRRRcC`s |jS(N(R(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRsRcC`s|j}|tkr"|jjS|dk rA|j|jS|jj}|r|jjg|D]}|t f^qc}x |D]}d||||>> 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]] RN(R?RR8ttolistRRQRRRR RRR R(RBR#R?RR%R*RR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs$     +     cC`s|j|ddS(s| This function is a compatibility alias for tobytes. Despite its name it returns bytes not strings. RR(ttobytes(RBR#R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyttostringscC`s|j|jd|S(sq 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 -------- 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() '\x01\x00\x00\x00?B\x0f\x00?B\x0f\x00\x04\x00\x00\x00' R(RQR(RBR#R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs&Rs%scC`stddS(s Save a masked array to a file in binary format. .. warning:: This function is not implemented yet. Raises ------ NotImplementedError When `tofile` is called. s)MaskedArray.tofile() not implemented yet.N(R(RBtfidtsepR ((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyttofile s cC`s|j}|j}|dkr3t|j|}n|jj}tjd|jdd|fd|fg}|j|d<|j|d<|S(s{ 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) >>> print(x) [[1 -- 3] [-- 5 --] [7 -- 9]] >>> print(x.toflex()) [[(1, False) (2, True) (3, False)] [(4, True) (5, False) (6, True)] [(7, False) (8, True) (9, False)]] RRR8R?N(RR?RRzRRRR8(RBtddtypeR?Rtrecord((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyttoflex/s'      cC`sId|jj}tt|jd}|t|j||jfS(sWReturn the internal state of the masked array, for pickling purposes. tCFi(RtfncRWRt __reduce__R]RR(RBtcft data_state((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt __getstate__fsc C`sl|\}}}}}}}tt|j||||f|jj|t|||f||_dS(skRestore the internal state of the masked array, for pickling purposes. ``state`` is typically the output of the ``__getstate__`` output, and is a 5-tuple: - class name - a tuple giving the shape of the data - a typecode for the data - a binary string for the data - a binary string for the mask. N(RWRt __setstate__R?RyR#( RBtstateR%tshpttyptisftrawtmsktflv((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRos ""cC`s%t|j|jddf|jfS(s6Return a 3-tuple for pickling a MaskedArray. iR(i(t_mareconstructRRR(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRscC`sddlm}tjt||dt}|dkrCi}n||t|( R>RRRR0R=RRRR(RBtmemoRtcopiedR1tv((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt __deepcopy__s  N(RRRRKRt _defaultmaskRt_defaulthardmaskRRR"R#RR=RR^RRR:RRtpropertyRtsetterRRt _set_maskRR<RRt recordmaskR`RRRt sharedmaskRt baseclassRR8R;RRRR+RR#RQR:R9R)RUtsyst version_infotmajorR*RRORYR\R^R`RaRbRcRdReRfRgRhRiRjRkRlRmRnRoRpRuRvRwRyRzR{R}R|RR~RR RBRRRRRcRRR"RRRRRDRRRCRR RRRR.R-R,RRRRRRRRRR7R>RGRRRRtTRRRRRRt torecordsRRRR(((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR s$5    [ 8Q x C  E              # '  L D    T  6             ! d . 8 F  ( e '5&(0( =  O)% L? :?%          3( 4  cC`sLtj|||}tjt|t|}|j||d|d|S(sbInternal function that builds a new MaskedArray from the information stored in a pickle. R<R(RRRy(RRt baseshapetbasetypeR8R?((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRscB`seZdZed d eeedZdZe deZ dZ dZ dZ e ZdZdZd d Zd ZRS( sN Fake a 'void' object to use for masked array with structured dtypes. c C`stj|d|d|d|}|j|}||_|tk rt|tjrc||_qytj||_Wqtk rt |} tj|d| d|_qXn|dk r||_ n|S(NR>R7R(( RR R:RRRRR?RRyRR#( RBR;R<RR#RR>R7R8R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs!     #  cC`stt|jdS(N((RWRR8(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRsRc C`su|j}t||trPtd|j|d||d|j|d|jS|tk rj||rjtS|j|S(s! Get the index. R;R<R#R( R?RRR}R8RRRR|(RBRR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs   cC`sU||j|<|jr8|j|ct|dtO|j|jq>Wt|S(s Transforms the mvoid object into a tuple. Masked fields are replaced by None. Returns ------- returned_tuple Tuple of fields N( R?RR8RRR#RRR(RBR?R*RaR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR s   "N(RRRRRRR=RRRR8RRRURRRRQR(((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs       cC`s t|tS(s 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(RG((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRh)s1R/cB`seZdZedZdZdZddZddZ dZ e j j dkrldZndZd Zd ZeZZZZZZ[d Zd Zd ZdZRS(cC`s"|jdk o!t|j|kS(N(t_MaskedConstant__singletonRR0(R5((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt__has_singletonescC`sj|jsctjd}tjt}t|j_t|j_t|d|j||_ n|j S(NgR<( t_MaskedConstant__has_singletonRR R=RRt writeableRR:R(R5R;R<((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRks   !cC`sQ|js"tt|j|S||jkr4nt|_tj||dS(N(RRWR/RRRR(RBR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR}s   cC`s|jtj||S(N(R:Rt__array_prepare__(RBRR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRscC`s|jtj||S(N(R:RR(RBRR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRscC`s ttjS(N(R RR(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRUsicC`s ttjS(N(RRR(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR*scC`s$|tjkrdStj|SdS(NR|(R/RR R(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRscC`s |jdfS(s.Override of MaskedArray's __reduce__. ((R(RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRscC`s|S(N((RBRL((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt__iop__scO`s|S(s: Copy is a no-op on the maskedconstant, as it is a scalar ((RBR_R`((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR>scC`s|S(N((RB((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt__copy__scC`s|S(N((RBR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRscC`si|js%tt|j||S||jkrLtdj|ntt|j||SdS(Ns$attributes of {!r} are not writeable(RRWR/t __setattr__RR9R (RBtattrR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs  N(RRRRt classmethodRRRRRRURRRR*RRRRmRnRoRuRvRwR>RRR(((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR/as$            c C`sFt|d|d|d|d| d|d|d|d| d |d | S( s~ Shortcut to MaskedArray. The options are in a different order for convenience and backwards compatibility. R<RR>R7RRR#RRR(R( R;RR>RR<R#RRRR7R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR s   cC`s0t|}|tkrtS|jr,tStS(s 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=999999) >>> 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=999999) >>> 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 (R\RRR"R=(RGR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRjs -   t_extrema_operationcB`s;eZdZdZddZejdZdZ RS(s Generic class for maximum/minimum functions. .. note:: This is the base class for `_maximum_operation` and `_minimum_operation`. cC`s,tt|j|||_||_dS(N(RWRRCRQtfill_value_func(RBRTRQR#((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRC"s cC`sW|dkr;tjdj|jtdd|j|St|j||||S(sExecutes the call behavior.sNSingle-argument form of np.ma.{0} is deprecated. Use np.ma.{0}.reduce instead.RiN( RRRR RRRRRQ(RBR)R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRH's    cC`s:t|dtdt}t|}|tjkrm|jdkrmtjdj |j t ddd }n|tjk rt d|}n t }|tkr|jj||}n{|j|j|jt|}|jj||}tjj||}t|dr'||_n|r6t}n|S( s#Reduce target along the given axis.R>R7isIn the future the default for ma.{0}.reduce will be axis=0, not the current None, to match np.{0}.reduce. Explicitly pass 0 or None to silence this warning.RiRpR?N(R RR=R\RR RRRR RRRR.RRRRQRR:R0RFRtRR?R|(RBRoRpRR`Rr((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR2s,      !  cC`st|}t|}|tkr9|tkr9t}n*t|}t|}tj||}|jjt|t|}t|ts|j t}n||_ |S(s<Return the function applied to the outer product of a and b.( R\RR]RvRRRQRRR:R?(RBR)RRmRnRR*((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRTs     ! N( RRRRCRRHRR RR(((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs   "cC`s|tjkrin i|d6}y#|jd|d|d||SWn9ttfk rt|jd|d|d||SXdS(NRRpR#R(RR RR9RR0(RRpRR#RR`((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRds "#cC`s|tjkrin i|d6}y#|jd|d|d||SWn9ttfk rt|jd|d|d||SXdS(NRRpR#R(RR RR9RR0(RRpRR#RR`((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRps "#cC`s|tjkrin i|d6}y |j|d|d||SWn9ttfk r}t|jd|d|d||SXdS(NRRR#Rp(RR RR9RR0(RRpRR#RR`((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR}s " t _frommethodcB`s,eZdZedZdZdZRS(s Define functions from existing MaskedArray methods. Parameters ---------- methodname : str Name of the method to transform. cC`s%||_|j|_||_dS(N(RtgetdocRtreversed(RBt methodnameR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRCs cC`smtt|jdp'tt|jd}|jt|}|dk rid|t|ddf}|SdS(s<Return the doc of the function (from the doc of the method).s %s %sRN(RRRRRR(RBtmetht signatureR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs cO`s|jr-t|}|d|}|d Returns element-wise base array raised to power from second array. This is the masked array version of `numpy.power`. For details see `numpy.power`. See Also -------- numpy.power Notes ----- The *out* argument to `numpy.power` is not supported, `third` has to be None. s3-argument power not supported.RIRDR@N(RRR\R{R[RRR0RRERRFRR:R^RuR>RRRR|RvR?R"R#R8( R)RtthirdRmRnRtfatfbRR*R@((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs2     0 !     Rc C`stj|}|tjkr-t|}nt|trd|jd|d|d|d|d|S|jd|d|d|SdS(s)Function version of the eponymous method.RpRRRR#N(RR0R RRRR.(R)RpRRRR#((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR.s ic C`stj|dtdt}|d kr<|j}d}nt|trv|jd|d|d|d|d|n|jd|d|d||S( s)Function version of the eponymous method.R>R7iRpRRRR#N(RR R=RRRRR(R)RpRRRR#((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR s   cC`st|jS(s Return all the non-masked data as a 1-D array. This function is equivalent to calling the "compressed" method of a `MaskedArray`, see `MaskedArray.compressed` for details. See Also -------- MaskedArray.compressed Equivalent method. (R0R:(RG((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR:0s cC`stjg|D]}t|^q |}t|}|j|}x(|D]}t|tk rMPqMqMW|Stjg|D]}t|^q~|}|j|j }t ||_ |S(sK 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) ( RR;R[R6R:R\RR]RRRR?(R2RpR)RaR3R;RGtdm((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR;@s)+  +cC`sLtj||jt}t|tk rHtj|j||_n|S(s 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. (RRFR:RR\RR?(RR1R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRF|s cC`sat||}t|tr]|j}|j}||_|jtk r]||j_q]n|S(s Expand the shape of an array. Expands the shape of the array by including a new axis before the one specified by the `axis` parameter. This function behaves the same as `numpy.expand_dims` but preserves masked elements. See Also -------- numpy.expand_dims : Equivalent function in top-level NumPy module. Examples -------- >>> import numpy.ma as ma >>> x = ma.array([1, 2, 4]) >>> x[1] = ma.masked >>> x masked_array(data = [1 -- 4], mask = [False True False], fill_value = 999999) >>> np.expand_dims(x, axis=0) array([[1, 2, 4]]) >>> ma.expand_dims(x, axis=0) masked_array(data = [[1 -- 4]], mask = [[False True False]], fill_value = 999999) The same result can be achieved using slicing syntax with `np.newaxis`. >>> x[np.newaxis, :] masked_array(data = [[1 -- 4]], mask = [[False True False]], fill_value = 999999) (t n_expand_dimsRRRR:R?R(RGRpR*t new_shape((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs(   cC`sit|}|tkr:tjt||}t|Stjt|d|}t|d|SdS(s 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 iR<N(R\RRFRlRQR}(R)RRRa((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRls   cC`sit|}|tkr:tjt||}t|Stjt|d|}t|d|SdS(s 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 iR<N(R\RRFRRQR}(R)RRRa((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs   cC`sQy|j||d|SWn0tk rLt|dtj||d|SXdS(s Set storage-indexed locations to corresponding values. This function is equivalent to `MaskedArray.put`, see that method for details. See Also -------- MaskedArray.put RR>N(RR9R R(R)RdRR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs  cC`s8t|ts!|jt}nt|t|}}t|tkr|tk rt|_t|j |j |_ t j |j |d|qn|jr|tk r|j j}t j ||d||j|O_qn4|tkrt|}nt j |j |d|t j |j|d|dS(sQ 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`. RN(RRR:R[R\RR=RRzRRR?RR]RR>R<R]R8(R)R<RtvaldatatvalmaskR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs$     cC`sHy|j|SWn0tk rCt|dtj|jtSXdS(s 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) R>N(RR9R RR:R(R)R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR$s# RcC`sZy|j|d|SWn<tk rUt|dtj|d|}|jtSXdS(s Returns an array containing the same data with a new shape. Refer to `MaskedArray.reshape` for full documentation. See Also -------- MaskedArray.reshape : equivalent function RR>N(RR9R RR:R(R)RRt_tmp((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRMs  !cC`sgt|}|tk r-tj||}ntj||jt|}|jrc||_n|S(s4 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)) array([[1, 2, 3], [4, 1, 2], [3, 4, 1]]) >>> 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) (R\RRRR:R6RR?(RGRRR*((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR`s7  !  cC`s,tjdtjddtjt|S(sd maskedarray version of the numpy function. .. note:: Deprecated since 1.10.0 s7`rank` is deprecated; use the `ndim` function instead. Ri(RRRtVisibleDeprecationWarningRR[(R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs cC`stjt|S(s5 maskedarray version of the numpy function. (RRR[(R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRscC`stjt|S(s*maskedarray version of the numpy function.(RRR[(R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRscC`stjt||S(s*maskedarray version of the numpy function.(RRR[(RRp((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRsc C`s|tk|tkfjt}|dkr<tdn|dkrRt|St|t}t|}t|}t|}t|}t|} |t kr|t k rt j dd|j }t j dd| j }nK|t kr3|t k r3t j dd|j }t j d d|j } nt j|||} t j||| } t j|t j d d| j | } t| } t| d| S( s Return a masked array with elements from x or y, depending on condition. Returns a masked array, shaped like condition, where the elements are from `x` when `condition` is True, and from `y` otherwise. If neither `x` nor `y` are given, the function returns a tuple of indices where `condition` is True (the result of ``condition.nonzero()``). Parameters ---------- condition : array_like, bool The condition to meet. For each True element, yield the corresponding element from `x`, otherwise from `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 or tuple of ndarrays The resulting masked array if `x` and `y` were given, otherwise the result of ``condition.nonzero()``. See Also -------- numpy.where : Equivalent function in the top-level NumPy module. Examples -------- >>> x = np.ma.array(np.arange(9.).reshape(3, 3), mask=[[0, 1, 0], ... [1, 0, 1], ... [0, 1, 0]]) >>> print(x) [[0.0 -- 2.0] [-- 4.0 --] [6.0 -- 8.0]] >>> np.ma.where(x > 5) # return the indices where x > 5 (array([2, 2]), array([0, 2])) >>> print(np.ma.where(x > 5, x, -3.1416)) [[-3.1416 -- -3.1416] [-- -3.1416 --] [6.0 -- 8.0]] is)Must provide both 'x' and 'y' or neither.iRR<((((((R RBR=RRRQRR[R]R|RRRRRRR}( RRGRtmissingRtxdtydtcmtxmtymR;R<((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs,1!        ' c C`sd}d}t|d}g|D]}||^q(}g|D]}||^qG} tj||d|} tt| t|dddt} tj|| d|d|jt} |dk rt |tr|j | n|S| j | | S( s6 Use an index array to construct a new array from a set of choices. Given an array of integers and a set of n choice arrays, this method will create a new array that merges each of the choice arrays. Where a value in `a` is i, the new array will have the value that choices[i] contains in the same place. Parameters ---------- a : 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) cS`s|tkrtSt|S(s,Returns the filled array, or True if masked.(R|R=RQ(RG((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pytfmaskMs cS`s|tkrtSt|S(s:Returns the mask, True if ``masked``, False if ``nomask``.(R|R=R\(RG((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pytnmaskSs iRR>RRN( RQRR6RxR{R\R=R:RRRR( RdtchoicesRRRRRRGtmasksR;t outputmaskRa((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR6 s-  '  cC`sa|dkrtj|||Stjt|||t|drYt||_n|SdS(s Return a copy of a, rounded to 'decimals' places. When 'decimals' is negative, it specifies the number of positions to the left of the decimal point. The real and imaginary parts of complex numbers are rounded separately. Nothing is done if the array is not of float type and 'decimals' is greater than or equal to 0. Parameters ---------- decimals : int Number of decimals to round to. May be negative. out : array_like Existing array to use for output. If not given, returns a default copy of a. Notes ----- If out is given and does not have a mask attribute, the mask of a is lost! R?N(RRRR[RR\R?(R)RR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRks  cC`st|dt}|jdkr0tdnt|}|tksU|j rY|S|j}|jj |_|st |t j |d>> import numpy.ma as ma >>> a = np.zeros((3, 3), dtype=int) >>> a[1, 1] = 1 >>> a array([[0, 0, 0], [0, 1, 0], [0, 0, 0]]) >>> a = ma.masked_equal(a, 1) >>> a masked_array(data = [[0 0 0] [0 -- 0] [0 0 0]], mask = [[False False False] [False True False] [False False False]], fill_value=999999) >>> ma.mask_rowcols(a) masked_array(data = [[0 -- 0] [-- -- --] [0 -- 0]], mask = [[False True False] [ True True True] [False True False]], fill_value=999999) R7is&mask_rowcols works for 2D arrays only.iiiN(Nii(R RRRR\RR"RR?R>R|RtuniqueR(R)RpRt maskedval((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt mask_rowcolssK   &c C`sz|rE|jdkrE|jdkrEt|d}t|d}nt|}t|}|dkrtjt|dt|d}tj||}|jdkrtj|}n|jt ||}|j ||Stjt|dt|d|j }|j j |j krFtj|j t|_ntj|||jtj|j|j|SdS(s 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. .. note:: Works only with 2-D arrays at the moment. 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 = ma.array([[1, 2, 3], [4, 5, 6]], mask=[[1, 0, 0], [0, 0, 0]]) >>> b = ma.array([[1, 2], [3, 4], [5, 6]], mask=[[1, 0], [0, 0], [0, 0]]) >>> np.ma.dot(a, b) masked_array(data = [[21 26] [45 64]], mask = [[False False] [False False]], fill_value = 999999) >>> np.ma.dot(a, b, strict=True) masked_array(data = [[-- --] [-- 64]], mask = [[ True True] [ True False]], fill_value = 999999) iiiN(RRR]RRRRQR1R:R6RR8R<RRLRR?Ru( R)RRRtamtbmRaRR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs&=$   $ *cC`smt|d}t|d}|jdkr9d|_n|jdkrTd|_ntj||jtS(s 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. ii(i(i(RQRRRReR:R(R)RRR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyReAs  s Masked values are replaced by 0.cC`st|dj}t|dj}tj||}t|}t|}|tkrv|tkrvt|St|}t|}tdtjd|d|dd}t|d|S(s*maskedarray version of the numpy function.iiR>R<( RQRRRR\RR}R]Rx(R)RRRRaRmRnR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRUs     *cC`s|r|t|tjtj|dtd||tjtj|dtt|d|B}|t|t|d|}nE|t|t|}|t|dt|dd|}t|d|S(s: Helper function for ma.correlate and ma.convolve RRiR<(R]RRRRR[RQR}(RR)RRtpropagate_maskR<R;((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt_convolve_or_correlategs04$'tvalidcC`sttj||||S(s 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. (R RR?(R)RRR ((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR?zsRcC`sttj||||S(s 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. (R RR=(R)RRR ((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR=scC`stt|t|}|tkr[t|}t|}tj||}|jS|rt|}t|}tj||}t|d|dt}|j t jdStSdS(s 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 = 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 = array([1e10, 1e-7, -42.0]) >>> b array([ 1.00000000e+10, 1.00000000e-07, -4.20000000e+01]) >>> ma.allequal(a, b, fill_value=False) False >>> ma.allequal(a, b) True R<R>N( R{R\RR[RFRNRR RRQR=R(R)RR#RRGRRaR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs*      c C`st|dt}t|dt}tj|d}|j|kr`t|d|dt}ntt|t|}tjt|dtd|jt} tj | ttj|tkstStj | stt t ||||t ||} tj | Stj t|| || k|sFtS|| }|| }tt t ||||t ||} tj | S(s- 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 = 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 = ma.array([1e10, 1e-8, -42.0], mask=[0, 0, 1]) >>> ma.allclose(a, b) False >>> a = ma.array([1e10, 1e-8, 42.0], mask=[0, 0, 1]) >>> b = ma.array([1.00001e10, 1e-9, -42.0], mask=[0, 0, 1]) >>> ma.allclose(a, b) True >>> ma.allclose(a, b, masked_equal=False) False Masked values are not compared directly. >>> a = ma.array([1e10, 1e-8, 42.0], mask=[0, 0, 1]) >>> b = ma.array([1.00001e10, 1e-9, 42.0], mask=[0, 0, 1]) >>> ma.allclose(a, b) True >>> ma.allclose(a, b, masked_equal=False) False R>g?RR<( R}RRt result_typeRR{R\tisinfRQRR"RnR( R)RR~RRRGRRRtxinfRa((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRs(H*''  &  ' c C`s4|p d}t|d|dtdtdtd|S(s  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)) RRR>RR7R(R}RR=(R)RR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR1Ss- c C`sPt|tr.|dks*||jkr.|St|d|dtdtdtS(s 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)) RR>RR7N(RRRRR}RR=(R)R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR0s-*cC`s&tjdjd|tdddS(Ns9np.ma.{method} is deprecated, use pickle.{method} insteadRRi(RRR R(R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyt _pickle_warns  cC`sXtdt|dsDt|d}tj||WdQXntj||dS(s Pickle a masked array to a file. This is a wrapper around ``cPickle.dump``. Parameters ---------- a : MaskedArray The array to be pickled. F : str or file-like object The file to pickle `a` to. If a string, the full path to the file. RJtreadlinetwN(RRtopentpickleRJ(R)R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRJs  cC`stdtj|S(s Return a string corresponding to the pickling of a masked array. This is a wrapper around ``cPickle.dumps``. Parameters ---------- a : MaskedArray The array for which the string representation of the pickle is returned. RK(RRRK(R)((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRKs cC`sRtdt|dsAt|d}tj|SWdQXn tj|SdS(sz Wrapper around ``cPickle.load`` which accepts either a file-like object or a filename. Parameters ---------- F : str or file The file or file name to load. See Also -------- dump : Pickle an array Notes ----- This is different from `numpy.load`, which does not use cPickle but loads the NumPy binary .npy format. RoRRN(RRRRRo(R((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRos  cC`stdtj|S(s Load a pickle from the current string. The result of ``cPickle.loads(strg)`` is returned. Parameters ---------- strg : str The string to load. See Also -------- dumps : Return a string corresponding to the pickling of a masked array. Rp(RRRp(tstrg((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRps RcC`stddS(Ns1fromfile() not yet implemented for a MaskedArray.(R(tfileRRBR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pytfromfilescC`st|dd|dS(s 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), (0, False, 0.0)], [(0, False, 0.0), (0, False, 0.0)]], dtype=[('_data', '>> y = np.ma.fromflex(rec2) >>> y masked_array(data = [[0 0] [0 0]], mask = [[False False] [False False]], fill_value = 999999) R8R<R?(R}(tfxarray((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRY s>t _convert2macB`s2eZdZdZddZdZdZRS(s Convert functions from numpy to numpy.ma. Parameters ---------- _methodname : string Name of the method to transform. cC`s4tt||_|j|_|p*i|_dS(N(RRt_funcRRt_extras(RBRR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRCnscC`sZt|jdd}t|j}|rV|rId|jj|f}n||}n|S(s<Return the doc of the function (from the doc of the method).Rs%s%s N(RRRRR(RBRR((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyRss cO`s|j}t|j|}x!|D]}|j|||>> import numpy.ma as ma >>> a = ma.masked_values([1, 2, 3], 2) >>> b = ma.masked_values([[4, 5, 6], [7, 8, 9]], 7) >>> print(ma.append(a, b)) [1 -- 3 4 5 6 -- 8 9] (R;(R)RRp((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyR#s%('Rt __future__RRRRRZRttextwrapRt functoolsRRR?t __builtin__tnumpyRtnumpy.core.umathR<RFtnumpy.core.numerictypest numerictypestntypesRRRRRR R R tnumpy.lib.function_baseR t numpy.compatR R RRRRRRtnumpy.core.multiarrayRtnumpy.core.numericRRtcPicklet__all__RRt FutureWarningRRRRRjRRR=RRt datetime64t timedelta64t_minvalsRRtfloat32tfloat64R1tinft_maxvalsRttypeDictRRRRERRRRR(RR+R8RRQR6R[tget_dataRRRZR[R RARIRKRPRRRSRVRcRxROR<RR@RR)R(RRARRRRPRRUR5RR/RuRRqRsRrR'R%R&R+RRRR*RNRRnR_RmR^RtRRvRRwR2R3R4RaRIRRVRRWRR}RRyR\tget_maskR]RiRRRxRzR{RSRRRRRRRR~RRRRRRRRR.tdedentR;RRTRRRRRRhRkRgR/R|RR}RjRRRRRRR!R R"R9RCRDR>RGR`RcRRRRRRRRRRRRRRRRBRRR-R,R.RR:R;RFRlRRRRRRRRRRRR6RRRReRfRRR R?R=RRR1R0RRJRKRoRpRNRRYRR$R7RHRLRMRXRZRbRdRt ones_likeRRt zeros_likeR#(((s,/tmp/pip-build-fiC0ax/numpy/numpy/ma/core.pyts       ..               $" 6 6   7  3 3 + A .  4A JL                      ! = 7 D Y 2B 9 u       ( (=P /0        8 -r  4i     :K   )                       3      <  2    ' )  @    TK ^T       :g2 6     A,!  !    !  !