
    Khn             
          % S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKJ	r	  SSK
rSSKJs  Jr  SSKJs  Jr  SSKJr  SSK
JrJrJrJrJrJrJr  SSK
JrJrJrJ r   SSK!J"r"  SSK#J$r$J%r%  SS	K&J'r'  / S
Qr(\RR                  r*\*" S5      r+ " S S\,5      r-S r.S r/S r0 " S S\15      r2 " S S\25      r3SSSSSSSSSS.	r4S H;  r5\Rl                  " S\55      \4S\5-   S -   '   \Rn                  " S\55      \4S!\5-   S -   '   M=     \Rp                  \Rr                  \Rt                  \Rv                  \Rx                  \Rz                  \R|                  /r?0 r@\	\A\B4   \CS"'   0 rD\	\A\B4   \CS#'   \R                  R                  5        GH   rG\R                  " \G5      rI\IR                  S$;   a9  \R>                  " \R                  5      rL\LR                  S%-   \LR                  srOrPO\R                  " \I\R                  5      (       a,  \R>                  " \G5      rL\LR                  \LR                  srOrPOi\R                  " \I\R                  5      (       a,  \R@                  " \G5      rL\LR                  \LR                  srOrPO\IR                  S&:X  a  S'u  rOrPOS(u  rOrP\O\@\G'   \P\D\G'   GM#     \@rT\TR                  \?SS)  V s/ s H  o \R                  * 4PM     sn 5        \TR                  \?S*S  V s/ s H#  o \W" \R                  * \R                  * 5      4PM%     sn 5        \DrX\XR                  \?SS)  V s/ s H  o \R                  74PM     sn 5        \XR                  \?S*S  V s/ s H#  o \W" \R                  7\R                  75      4PM%     sn 5        C?S+ rYS, rZS- r[S. r\S/ r]S0 r^S1 r_S2 r`S3 raS4 rbS5 rcSS6 jrdS7 reSS8 jrf\frg\+SS4S9 jrhS: ri0 rj0 rk " S; S<5      rl " S= S>5      rm " S? S@5      rn " SA SB5      ro " SC SD5      rp " SE SF5      rq " SG SH\q5      rr " SI SJ\q5      rs " SK SL\q5      rt\r" \R                  5      ru\r" \R                  5      rv\r" \R                  5      rw\r" \R                  5      rx\r" \R                  5      ry\r" \R                  5      rz\r" \R                  5      r{\r" \R                  5      r|\r" \R                  5      r}\r" \R                  5      =rr~\r" \5      r\r" \GR                   5      r\r" \GR                  5      r\r" \GR                  5      r\r" \GR                  5      r\r" \GR                  5      r\r" \GR
                  5      r\r" \GR                  SM\p" SM5      5      r\r" \GR                  SN\o" SM5      5      r\r" \GR                  SN\o" SM5      5      r\r" \GR                  SN\o" SM5      5      r\r" \GR                  SM\m" SO5      5      r\r" \GR                  SM\l" SPSN5      5      r\r" \GR                  SM\l" SPSN5      5      r\r" \GR                  SN\p" SN5      5      r\r" \GR                  SM\l" SQSR5      5      r\s" \GR                  5      r\s" \GR                   5      r\s" \GR"                  S%S%5      r\s" \GR$                  SMSN5      r\s" \GR&                  5      rS\l        \s" \GR*                  5      rS\l        \s" \GR,                  5      rS\l        \s" \GR.                  5      rS\l        \s" \GR0                  5      rS\l        \s" \GR2                  5      rS\l        \s" \GR4                  5      r\s" \GR4                  S%S%5      GR(                  r\s" \GR8                  5      r\GR(                  r\s" \GR<                  5      r\s" \GR>                  5      r\s" \GR@                  5      r\s" \GRB                  5      r\s" \GRD                  5      r\t" \GRF                  \n" 5       SS%5      r\t" \GRH                  \n" 5       SS%5      r\t" \GRJ                  \n" 5       SS%5      r\t" \GRL                  \n" 5       SS%5      r\t" \GRN                  \n" 5       SS%5      r\t" \GRP                  \n" 5       SS%5      rSS rST rSU rSV r\rSW rSX rSY rSZS\*4S[ jrSS\ jrS] rSS^ jrS_ r\R4                  4S` jrSSa jrSSb jrSSc jrSSd jrSSe jrSSf jrSSg jrSSh jrSSi jrSSj jrSSk jrSSl jr " Sm Sn5      r\" So5      rSp r\" \GR                  " Sq5      \GR                  " Sr5      \GR                  " Ss5      \GR                  " St5      Su9rSv rSw rSSx jr " Sy Sz5      r\'" S{5       " S| S}\5      5       rS~ r " S S\5      rS r\r\r " S S\5      r\" 5       =rr\rSSZS\+SSSZSSS4
S jr\R                   \l         S r " S S\q5      rSSS\R4                  4S jrM\R                  R                   \Ml         SSS\R4                  4S jrN\R                  R                   \Nl         SSS\R4                  4S jr\GR                  R                   \l          " S S5      r\" S5      r\" S5      =rr\" S5      r\" SSS9r\" S5      r\" S5      r\" S5      r\" S5      r\" S5      r\" S5      r\" \GR                  \\^5      r\" S5      r\" \GR                  \\]5      r\" S5      r\" S5      r\" S5      r\" S5      r\" S5      r\" S5      r\" S5      r\" S5      r\" S5      r\" S5      r\" S5      r\" S5      r\" S5      rSS jrSS jr\" S5      r\" S5      r\R4                  SSSS4SS.S jjr\GR                  R                   \l         SSS.S jjrS rSS jrSS jrS rS Gr SS jGrS GrSS jGrSS jGrS GrS Gr\GR                  R                   G\l         S Gr\GR                  R                   G\l         SS jGr\GR                  R                   G\l         S%S\R4                  \R4                  4S jGr	\\4S jGr
SS jGrSS jGrG\GrS GrSS jGrS Gr\/" \GR                   R                   S5      G\l         G\GrS Gr\/" \GR$                  R                   S5      G\l         G\GrS GrSS jGrSS jGrSS jGrSS jGrS(S jGrSS jGrG\SS4S jGrS Gr " S S5      GrG\" S\" SSZS9SSS9GrG\" S\" SSZS9SSS9Gr G\" S\" SSZS9SSS9Gr!G\" SSSS9Gr"G\" SSSS9Gr#G\" SSSS9Gr$G\" S\" SSZS9SSS9Gr%G\" S\" SSZS9SSS9Gr&G\" S\" SSZS9SSS9Gr'G\" SSSS9Gr(G\" S\" SSZS9SSS9Gr)G\" S\" SSZS9SSS9Gr*G\" SSSS9Gr+SS jGr,gs  sn f s  sn f s  sn f s  sn f )a  
numpy.ma : a package to handle missing or invalid values.

This package was initially written for numarray by Paul F. Dubois
at Lawrence Livermore National Laboratory.
In 2006, the package was completely rewritten by Pierre Gerard-Marchant
(University of Georgia) to make the MaskedArray class a subclass of ndarray,
and to improve support of structured arrays.


Copyright 1999, 2000, 2001 Regents of the University of California.
Released for unlimited redistribution.

* Adapted for numpy_core 2005 by Travis Oliphant and (mainly) Paul Dubois.
* Subclassing of the base `ndarray` 2006 by Pierre Gerard-Marchant
  (pgmdevlist_AT_gmail_DOT_com)
* Improvements suggested by Reggie Dugard (reggie_AT_merfinllc_DOT_com)

.. moduleauthor:: Pierre Gerard-Marchant

    N)Dict)
multiarray)ndarrayamaxaminiscomplexobjbool__NoValueangle)arrayexpand_dimsiinfofinfo)normalize_axis_tuple)
getargspecformatargspec)
set_module)MAError	MaskErrorMaskTypeMaskedArrayabsabsoluteaddallallcloseallequalalltruer   r   r   anom	anomaliesanyappendarangearccosarccosharcsinarcsinharctanarctan2arctanhargmaxargminargsortaroundr   
asanyarrayasarraybitwise_and
bitwise_orbitwise_xorr	   ceilchooseclipcommon_fill_valuecompress
compressedconcatenate	conjugateconvolvecopy	correlatecoscoshcountcumprodcumsumdefault_fill_valuediagdiagonaldiffdivideempty
empty_likeequalexpr   fabsfilledfix_invalidflatten_maskflatten_structured_arrayfloorfloor_dividefmod
frombufferfromflexfromfunctiongetdatagetmaskgetmaskarraygreatergreater_equalharden_maskhypotidentityidsindicesinnerinnerproductisMAisMaskedArrayis_mask	is_maskedisarray
left_shiftless
less_equalloglog10log2logical_andlogical_not
logical_orlogical_xor	make_maskmake_mask_descrmake_mask_nonemask_ormaskedmasked_arraymasked_equalmasked_greatermasked_greater_equalmasked_insidemasked_invalidmasked_lessmasked_less_equalmasked_not_equalmasked_objectmasked_outsidemasked_print_optionmasked_singletonmasked_valuesmasked_wheremaxmaximummaximum_fill_valuemeanminminimumminimum_fill_valuemodmultiplymvoidndimnegativenomasknonzero	not_equalones	ones_likeouterouterproductpowerprodproductptpputputmaskravel	remainderrepeatreshaperesizeright_shiftroundround_set_fill_valueshapesinsinhsizesoften_masksometruesortsqrtsqueezestdsubtractsumswapaxestaketantanhtrace	transposetrue_dividevarwherezeros
zeros_likec                       \ rS rSrSrg)MaskedArrayFutureWarningR    N)__name__
__module____qualname____firstlineno____static_attributes__r       ?/var/www/html/env/lib/python3.13/site-packages/numpy/ma/core.pyr   r   R   s    r   r   c                 Z    U R                   S::  a  g[        R                  " S[        SS9  g)a  
Adjust the axis passed to argsort, warning if necessary

Parameters
----------
arr
    The array which argsort was called on

np.ma.argsort has a long-term bug where the default of the axis argument
is wrong (gh-8701), which now must be kept for backwards compatibility.
Thankfully, this only makes a difference when arrays are 2- or more-
dimensional, so we only need a warning then.
   zIn the future the default for argsort will be axis=-1, not the current None, to match its documentation and np.argsort. Explicitly pass -1 or None to silence this warning.   
stacklevelN)r   warningswarnr   )arrs    r   _deprecate_argsort_axisr   U   s4     xx1}  	B %		4
 r   c                     U c  gUc  U $ [         R                  " S[        R                  " U 5      5      nS[        R                  " U5      -  nSR	                  USS U/-   USS -   5      $ )z1
Adds a Notes section to an existing docstring.

Nz\n\s*?Notes\n\s*?-----z

Notes
-----
%s
 r   )resplitinspectcleandocjoin)
initialdocnote	notesplitnotedocs       r   doc_noter   q   sp    
 |2G4D4DZ4PQI&)9)9$)??G779Ra=G9,y}<==r   c                 P     [        [        U 5      6 nU$ ! [         a    Sn U$ f = f)z
Get the signature from obj

r   )r   r   	TypeError)objsigs     r   get_object_signaturer      s7    
Z_- J  Js    %%c                       \ rS rSrSrSrg)r      z)
Class for masked array related errors.

r   Nr   r   r   r   __doc__r   r   r   r   r   r           	r   r   c                       \ rS rSrSrSrg)r      z!
Class for mask related errors.

r   Nr   r   r   r   r   r      r   r   r   Ty@xD        g@xDi?B ?s   N/As   ???zN/A)	bcfiOSuVU)YMWDhmsmsusnspsfsasNaTzM8[]zm8[_minvals_maxvalsMmr   r   )r   r   NN   c                 "  ^ ^ T R                   b8  [        U U4S jT R                    5       5      n[        R                  " UT S9S   $ T R                  (       a0  T R                  u  p4[        UT5      n[        R                  " XE5      $ T" T 5      $ )zJ
Recursively produce a fill value for `dtype`, calling f on scalar dtypes
c              3   j   >#    U  H(  n[         R                  " [        TU   T5      5      v   M*     g 7fN)npr   _recursive_fill_value).0namedtyper   s     r   	<genexpr>(_recursive_fill_value.<locals>.<genexpr>   s0      )'D .uT{A>??'s   03r  r   )namestupler  r   subdtyper  full)r  r   valssubtyper   subvals   ``    r   r  r     sz     {{
  )!KK) ) xxE*2..	&w2wwu%%xr   c                     [        U [        R                  5      (       a  U $ [        U S5      (       a  U R                  $ [        R                  " U 5      R                  $ )z3Convert the argument for *_fill_value into a dtype r  )
isinstancer  r  hasattrr/   r   s    r   _get_dtype_ofr"     sD    #rxx  
	g		yy}}S!'''r   c                 4    S n[        U 5      n[        X!5      $ )a  
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
--------
>>> import numpy as np
>>> np.ma.default_fill_value(1)
999999
>>> np.ma.default_fill_value(np.array([1.1, 2., np.pi]))
1e+20
>>> np.ma.default_fill_value(np.dtype(complex))
(1e+20+0j)

c                     U R                   S;   a#  [        R                  U R                  SS  S5      $ [        R                  U R                   S5      $ )Nr  r   r   )kinddefault_fillergetstrr  s    r   _scalar_fill_value.default_fill_value.<locals>._scalar_fill_value*  sB    ::!%%eiimS99!%%ejj#66r   r"  r  )r   r)  r  s      r   rD   rD      s    \7 #E ;;r   c                 @   ^^ UU4S jn[        U 5      n[        XC5      $ )Nc                 n   >  TU R                      $ ! [         a  n[        SU  ST S35      S eS nAff = f)NzUnsuitable type z for calculating .)typeKeyErrorr   )r  eextremumextremum_names     r   r)  0_extremum_fill_value.<locals>._scalar_fill_value6  sJ    	EJJ'' 	"5'):=/K	s    
4/4r+  )r   r2  r3  r)  r  s    ``  r   _extremum_fill_valuer5  4  s     #E ;;r   c                 $    [        U [        S5      $ )a  
Return the maximum value that can be represented by the dtype of an object.

This function is useful for calculating a fill value suitable for
taking the minimum of an array with a given dtype.

Parameters
----------
obj : ndarray, dtype or scalar
    An object that can be queried for it's numeric type.

Returns
-------
val : scalar
    The maximum representable value.

Raises
------
TypeError
    If `obj` isn't a suitable numeric type.

See Also
--------
maximum_fill_value : The inverse function.
set_fill_value : Set the filling value of a masked array.
MaskedArray.fill_value : Return current fill value.

Examples
--------
>>> import numpy as np
>>> import numpy.ma as ma
>>> a = np.int8()
>>> ma.minimum_fill_value(a)
127
>>> a = np.int32()
>>> ma.minimum_fill_value(a)
2147483647

An array of numeric data can also be passed.

>>> a = np.array([1, 2, 3], dtype=np.int8)
>>> ma.minimum_fill_value(a)
127
>>> a = np.array([1, 2, 3], dtype=np.float32)
>>> ma.minimum_fill_value(a)
inf

r   )r5  
min_fillerr!  s    r   r   r   B      b  Z;;r   c                 $    [        U [        S5      $ )a  
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 as np
>>> import numpy.ma as ma
>>> a = np.int8()
>>> ma.maximum_fill_value(a)
-128
>>> a = np.int32()
>>> ma.maximum_fill_value(a)
-2147483648

An array of numeric data can also be passed.

>>> a = np.array([1, 2, 3], dtype=np.int8)
>>> ma.maximum_fill_value(a)
-128
>>> a = np.array([1, 2, 3], dtype=np.float32)
>>> ma.maximum_fill_value(a)
-inf

r   )r5  
max_fillerr!  s    r   r   r   v  r8  r   c           	         [         R                  " U [        UR                  5      5      n / n[	        XR                  5       H  u  p4X   nUR
                  (       a  UR
                  S   nUR                  b%  UR                  [        [        X55      5      5        M[  UR                  [         R                  " X5S9R                  5       5        M     [        U5      $ )a  
Create a fill value for a structured dtype.

Parameters
----------
fillvalue : scalar or array_like
    Scalar or array representing the fill value. If it is of shorter
    length than the number of fields in dt, it will be resized.
dt : dtype
    The structured dtype for which to create the fill value.

Returns
-------
val : tuple
    A tuple of values corresponding to the structured fill value.

r   r  )r  r   lenr  zipr  r"   r  _recursive_set_fill_valuer   item)	fillvaluedtoutput_valuefvalr  cdtypes         r   r>  r>    s    $ 		)S]3ILIxx0??__Q'F<<#&?&M NO < A A CD 1 r   c                    [         R                  " U5      nU c2  [        U5      n UR                  S:X  a  [         R                  " U 5      n OUR
                  bs  [        U [        [         R                  45      (       a   [         R                  " XS9n O[         R                  " U [        S9n [         R                  " [        X5      US9n OI[        U [        5      (       a  UR                  S;  a  Sn[!        X1-  5      e [         R                  " XS9n [         R                  " U 5      $ ! [         a  nSn[        X0U4-  5      UeSnAff = f! ["        [        4 a  nSn[!        X0U4-  5      UeSnAff = f)z
Private function validating the given `fill_value` for the given dtype.

If fill_value is None, it is set to the default corresponding to the dtype.

If fill_value is not None, its value is forced to the given dtype.

The result is always a 0d array.

Nr   r  z"Unable to transform %s to dtype %sOSVUz6Cannot set fill value of string with array of dtype %sz(Cannot convert fill_value %s to dtype %s)r  r  rD   r%  uintr  r  r   voidr0   
ValueErrorobjectr   r>  r(  charr   OverflowError)
fill_valuendtyper1  err_msgs       r   _check_fill_valuerP    sS    XXfF'/
 ;;#,J		!j7BGG"455HZZ
A

 Jf=J";J"O(.0J j#&&FKKv,ENGG,--GZZ
A
 88J/  H> +?!?@aGH" ":. G Ev*> >?QFGs0   ?D+ E +
E5EEE6E11E6c                 P    [        U [        5      (       a  U R                  U5        g)a1  
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 as np
>>> import numpy.ma as ma
>>> a = np.arange(5)
>>> a
array([0, 1, 2, 3, 4])
>>> a = ma.masked_where(a < 3, a)
>>> a
masked_array(data=[--, --, --, 3, 4],
             mask=[ True,  True,  True, False, False],
       fill_value=999999)
>>> ma.set_fill_value(a, -999)
>>> a
masked_array(data=[--, --, --, 3, 4],
             mask=[ True,  True,  True, False, False],
       fill_value=-999)

Nothing happens if `a` is not a masked array.

>>> a = list(range(5))
>>> a
[0, 1, 2, 3, 4]
>>> ma.set_fill_value(a, 100)
>>> a
[0, 1, 2, 3, 4]
>>> a = np.arange(5)
>>> a
array([0, 1, 2, 3, 4])
>>> ma.set_fill_value(a, 100)
>>> a
array([0, 1, 2, 3, 4])

N)r  r   r   arM  s     r   r   r      s#    z ![!!	$
r   c                 b    [        U [        5      (       a  U R                  nU$ [        U 5      nU$ )zf
Return the filling value of a, if any.  Otherwise, returns the
default filling value for that type.

)r  r   rM  rD   )rS  results     r   get_fill_valuerV  B  s2     ![!! M $A&Mr   c                 >    [        U 5      n[        U5      nX#:X  a  U$ g)a  
Return the common filling value of two masked arrays, if any.

If ``a.fill_value == b.fill_value``, return the fill value,
otherwise return None.

Parameters
----------
a, b : MaskedArray
    The masked arrays for which to compare fill values.

Returns
-------
fill_value : scalar or None
    The common fill value, or None.

Examples
--------
>>> import numpy as np
>>> x = np.ma.array([0, 1.], fill_value=3)
>>> y = np.ma.array([0, 1.], fill_value=3)
>>> np.ma.common_fill_value(x, y)
3.0

N)rV  )rS  r   t1t2s       r   r7   r7   O  s%    4 
	B		B	x	r   c                     [        U S5      (       a  U R                  U5      $ [        U [        5      (       a  U $ [        U [        5      (       a  [
        R                  " U S5      $ [
        R                  " U 5      $ )a  
Return input as an `~numpy.ndarray`, with masked values replaced by
`fill_value`.

If `a` is not a `MaskedArray`, `a` itself is returned.
If `a` is a `MaskedArray` with no masked values, then ``a.data`` is
returned.
If `a` is a `MaskedArray` and `fill_value` is None, `fill_value` is set to
``a.fill_value``.

Parameters
----------
a : MaskedArray or array_like
    An input object.
fill_value : array_like, optional.
    Can be scalar or non-scalar. If non-scalar, the
    resulting filled array should be broadcastable
    over input array. Default is None.

Returns
-------
a : ndarray
    The filled array.

See Also
--------
compressed

Examples
--------
>>> import numpy as np
>>> import numpy.ma as ma
>>> x = ma.array(np.arange(9).reshape(3, 3), mask=[[1, 0, 0],
...                                                [1, 0, 0],
...                                                [0, 0, 0]])
>>> x.filled()
array([[999999,      1,      2],
       [999999,      4,      5],
       [     6,      7,      8]])
>>> x.filled(fill_value=333)
array([[333,   1,   2],
       [333,   4,   5],
       [  6,   7,   8]])
>>> x.filled(fill_value=np.arange(3))
array([[0, 1, 2],
       [0, 4, 5],
       [6, 7, 8]])

rN   r   )r   rN   r  r   dictr  r   rR  s     r   rN   rN   p  s_    d q(xx
##	Aw			At		xx3xx{r   c                  j   [        U 5      S:X  a-  U S   n[        U[        5      (       a  [        U5      nOb[        nO[U  Vs/ s H  n[        U5      PM     nnUS   n[	        U[        5      (       d  [        nUSS  H  n[	        XR5      (       d  M  UnM     UR
                  S:X  a  [        $ U$ s  snf )z
Return the youngest subclass of MaskedArray from a list of (masked) arrays.

In case of siblings, the first listed takes over.

r   r   NMaskedConstant)r<  r  r   r/  
issubclassr   )arraysr   rclsrS  arrclsclss         r   get_masked_subclassrc    s     6{aQic;''9DD#)*6a$q'6*ay$,,D!":C#$$  }}((K +s   B0c                      U R                   nU(       d  UR	                  [
        5      $ U$ ! [         a    [        R                  " U SUS9n N@f = f)a  
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 as np
>>> import numpy.ma as ma
>>> a = ma.masked_equal([[1,2],[3,4]], 2)
>>> a
masked_array(
  data=[[1, --],
        [3, 4]],
  mask=[[False,  True],
        [False, False]],
  fill_value=2)
>>> ma.getdata(a)
array([[1, 2],
       [3, 4]])

Equivalently use the ``MaskedArray`` `data` attribute.

>>> a.data
array([[1, 2],
       [3, 4]])

Nr=   subok)_dataAttributeErrorr  r   viewr   )rS  rf  datas      r   rX   rX     sM    V3ww yy!!K	  3xxE23s   ,  AAc                    [        XUSS9n [        R                  " [        R                  " U R                  5      5      nUR                  5       (       d  U $ U =R                  U-  sl        Uc  U R                  nX0R                  U'   U $ )a  
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
--------
>>> import numpy as np
>>> x = np.ma.array([1., -1, np.nan, np.inf], mask=[1] + [0]*3)
>>> x
masked_array(data=[--, -1.0, nan, inf],
             mask=[ True, False, False, False],
       fill_value=1e+20)
>>> np.ma.fix_invalid(x)
masked_array(data=[--, -1.0, --, --],
             mask=[ True, False,  True,  True],
       fill_value=1e+20)

>>> fixed = np.ma.fix_invalid(x)
>>> fixed.data
array([ 1.e+00, -1.e+00,  1.e+20,  1.e+20])
>>> x.data
array([ 1., -1., nan, inf])

T)r=   maskrf  )rx   r  rp   isfiniterg  r!   _maskrM  )rS  rl  r=   rM  invalids        r   rO   rO      sl    b 	QD9AnnR[[12G;;==GGwG\\
!GGGHr   c                     [        U [        5      =(       d=    [        U [        5      =(       a&    U =(       a    [        R                  " S U  5       5      $ )Nc              3   B   #    U  H  n[        U[        5      v   M     g 7fr  )r  r(  )r  r   s     r   r  /is_string_or_list_of_strings.<locals>.<genexpr>>  s     :c*Q,,cs   )r  r(  listbuiltinsr   )vals    r   is_string_or_list_of_stringsrv  ;  s>    sC  <T" ;s ;\\:c::=r   c                   $    \ rS rSrSrS rS rSrg)_DomainCheckIntervaliI  zn
Define a valid interval, so that :

``domain_check_interval(a,b)(x) == True`` where
``x < a`` or ``x > b``.

c                 *    X:  a  X!p!Xl         X l        g)z9domain_check_interval(a,b)(x) = true where x < a or y > bNrS  r   selfrS  r   s      r   __init___DomainCheckInterval.__init__R  s    5r   c                    [         R                  " SS9   [        R                  " [        R                  " XR
                  5      [        R                  " XR                  5      5      sSSS5        $ ! , (       d  f       g= f)Execute the call behavior.ignorero  N)r  errstateumathrq   r[   r   rj   rS  r|  xs     r   __call___DomainCheckInterval.__call__Y  sI     [[*##EMM!VV$<$)JJq&&$9; +**s   AA22
B rz  Nr   r   r   r   r   r}  r  r   r   r   r   rx  rx  I  s    ;r   rx  c                   $    \ rS rSrSrS rS rSrg)
_DomainTanib  zs
Define a valid interval for the `tan` function, so that:

``domain_tan(eps) = True`` where ``abs(cos(x)) < eps``

c                     Xl         g)z/domain_tan(eps) = true where abs(cos(x)) < eps)Neps)r|  r  s     r   r}  _DomainTan.__init__j  s    r   c                     [         R                  " SS9   [        R                  " [        R                  " [        R
                  " U5      5      U R                  5      sSSS5        $ ! , (       d  f       g= fExecutes the call behavior.r  r  N)r  r  r  rj   r   r?   r  r  s     r   r  _DomainTan.__call__n  s=    [[*::ennUYYq\:DHHE +**s   A	A((
A6r  Nr  r   r   r   r  r  b  s    Fr   r  c                   (    \ rS rSrSrSS jrS rSrg)_DomainSafeDivideit  z%
Define a domain for safe division.

Nc                     Xl         g r  	tolerance)r|  r  s     r   r}  _DomainSafeDivide.__init__z  s    "r   c                    U R                   c)  [        R                  " [        5      R                  U l         [        R
                  " U5      [        R
                  " U5      p![        R                  " SS9   [        R                  " U5      U R                   -  [        R                  " U5      :  sS S S 5        $ ! , (       d  f       g = f)Nr  )r   )	r  r  r   floattinyr0   r  r  r   r{  s      r   r  _DomainSafeDivide.__call__}  su     >>!XXe_11DNzz!}bjjm1[[X&>>!$t~~59JJ '&&s   6:B::
Cr  r  r  r   r   r   r  r  t  s    
#	Kr   r  c                   $    \ rS rSrSrS rS rSrg)_DomainGreateri  z,
DomainGreater(v)(x) is True where x <= v.

c                     Xl         g)z'DomainGreater(v)(x) = true where x <= vNcritical_valuer|  r  s     r   r}  _DomainGreater.__init__      ,r   c                     [         R                  " SS9   [        R                  " XR                  5      sSSS5        $ ! , (       d  f       g= fr  )r  r  r  rk   r  r  s     r   r  _DomainGreater.__call__  s.    [[*##A':':; +**	    ?
Ar  Nr  r   r   r   r  r    s    
-<r   r  c                   $    \ rS rSrSrS rS rSrg)_DomainGreaterEquali  z0
DomainGreaterEqual(v)(x) is True where x < v.

c                     Xl         g)z+DomainGreaterEqual(v)(x) = true where x < vNr  r  s     r   r}  _DomainGreaterEqual.__init__  r  r   c                     [         R                  " SS9   [        R                  " XR                  5      sSSS5        $ ! , (       d  f       g= fr  )r  r  r  rj   r  r  s     r   r  _DomainGreaterEqual.__call__  s,    [[*::a!4!45 +**r  r  Nr  r   r   r   r  r    s    
-6r   r  c                        \ rS rSrS rS rSrg)_MaskedUFunci  c                 v    Xl         UR                  U l        UR                  U l        UR                  U l        g r  )r   r   r   r   )r|  ufuncs     r   r}  _MaskedUFunc.__init__  s+    }}!..r   c                      SU R                    3$ )NzMasked version of )r   r|  s    r   __str___MaskedUFunc.__str__  s    #DFF8,,r   )r   r   r   r   N)r   r   r   r   r}  r  r   r   r   r   r  r    s    /-r   r  c                   6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )_MaskedUnaryOperationi  a  
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.

c                 `   > [         TU ]  U5        X l        X0l        U[        U'   U[
        U'   g r  )superr}  filldomainufunc_domainufunc_fills)r|  mufuncr  r  	__class__s       r   r}  _MaskedUnaryOperation.__init__  s.     	%V"Fr   c                    [        U5      nU R                  bm  [        R                  " SSS9   U R                  " U/UQ70 UD6nSSS5        [
        R                  " W5      ) nX`R                  U5      -  nU[        U5      -  nO?[        R                  " SSS9   U R                  " U/UQ70 UD6nSSS5        [        U5      nWR                  (       d  U(       a  [        $ U$ U[        La   [        R                  " XTUS9  UR                  [        U5      5      nXgl        UR!                  U5        U$ ! , (       d  f       N= f! , (       d  f       N= f! [         a     Naf = f)
Execute the call behavior.

Nr  rH   ro  r   )rX   r  r  r  r   r  rm  rY   r   rw   r   copytor   ri  rc  rn  _update_from)r|  rS  argskwargsdrU  r   masked_results           r   r  _MaskedUnaryOperation.__call__  s2   
 AJ;;" Hh?3D3F3 @ ''AQAOA Hh?3D3F3 @
A{{MF?		&1- $7$:;""1%G @? @?(  s)   D7E/E 7
E
E
E&%E&)r  r  r   N	r   r   r   r   r   r}  r  r   __classcell__r  s   @r   r  r    s    "#. .r   r  c                   P   ^  \ rS rSrSrS	U 4S jjrS rS
S jrS rSS jr	Sr
U =r$ )_MaskedBinaryOperationi  a  
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.

c                 b   > [         TU ]  U5        X l        X0l        S[        U'   X#4[
        U'   g)zZ
abfunc(fillx, filly) must be defined.

abfunc(x, filly) = x for all x to enable reduce.

N)r  r}  fillxfillyr  r  )r|  mbfuncr  r  r  s       r   r}  _MaskedBinaryOperation.__init__  s2     	 

#V$nFr   c                    [        U5      [        U5      pe[        R                  " 5          [        R                  " SSS9  U R                  " XV/UQ70 UD6nSSS5        [        U5      [        U5      pU[        L a1  U	[        L a  [        n
Oa[        R                  " [        U5      U	5      n
O@U	[        L a!  [        R                  " U[        U5      5      n
O[        R                  " X5      n
WR                  (       d  U
(       a  [        $ U$ U
[        La,  U
R                  5       (       a   [        R                  " XuSU
S9  UR                  [!        X5      5      nXl        [%        U[&        5      (       a  UR)                  U5        U$ [%        U[&        5      (       a  UR)                  U5        U$ ! , (       d  f       GNc= f! [         a     Nf = f)r  r  r  Nunsafecastingr   )rX   r  r  seterrr   rY   r   r  rq   rZ   r   rw   r!   r  	Exceptionri  rc  rn  r  r   r  )r|  rS  r   r  r  dadbrU  mambr   r  s               r   r  _MaskedBinaryOperation.__call__  sj    AJ
R[[]IIXx8VVB4T4V4F  AJ
R<V|$$\!_b96\  \!_5A  (A {{M F?quuww		&ha@
 $7$=>a%%&&q)  ;''&&q)K ]6  s   ,F3-G 3
G
GGc                    [        U5      n[        U5      n[        XR                  5      nUR                  S:X  a+  UR                  S5      nU[        La  [        USS9nSUl        U[        L a"  U R                  R                  Xb5      n[        nO9U R                  R                  XbUS9n[        R                  R                  XR5      nUR                  (       d  U(       a  [        $ U$ UR                  U5      n	Xl        U	$ )z*
Reduce `target` along the given `axis`.

r   r   Tr=   r   r  )rc  rY   rN   r  r   r   r   rs   r   reducer  ro   rw   ri  rn  )
r|  targetaxisr  tclassr   ttrmr	masked_trs
             r   r  _MaskedBinaryOperation.reduceN  s    
 %V,FO6::&77b=		!Aad+;q'BBqe4B""))!2Bxx	GGFO	r   c                    [        U5      [        U5      pCU R                  R                  X45      n[        U5      n[        U5      nU[        L a  U[        L a  [        nO5[        U5      n[        U5      n[        R                  R                  Xg5      nUR                  (       d  U(       a  [        $ U[        La  [        R                  " XSUS9  UR                  (       d  U$ UR                  [        X5      5      n	Xl        U	$ )z?
Return the function applied to the outer product of a and b.

r  )rX   r   r   rY   r   rZ   r  rq   r   rw   r  r  r   ri  rc  rn  )
r|  rS  r   r  r  r  r  r  r   masked_ds
             r   r   _MaskedBinaryOperation.outerl  s    
 AJ
RFFLL QZQZ<B&LAaBaB  &&r.AAMF?IIa1%wwH66-a34r   c                     [        U5      n[        XR                  5      nU R                  R	                  XB5      nUR                  U5      nU$ )zCAccumulate `target` along `axis` after filling with y fill
value.

)rc  rN   r  r   
accumulateri  )r|  r  r  r  r  rU  r  s          r   r  !_MaskedBinaryOperation.accumulate  sD    
 %V,6::&""1+F+r   )r  r  r   r   r  r   )r   r   r   r   r   r}  r  r  r   r  r   r  r  s   @r   r  r    s'    &--^<2	 	r   r  c                   6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )_DomainedBinaryOperationi  a  
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.

c                 n   > [         TU ]  U5        X l        X0l        X@l        U[
        U'   X44[        U'   g)zWabfunc(fillx, filly) must be defined.
abfunc(x, filly) = x for all x to enable reduce.
N)r  r}  r  r  r  r  r  )r|  dbfuncr  r  r  r  s        r   r}  !_DomainedBinaryOperation.__init__  s7     	 

%V$nFr   c                 z   [        U5      [        U5      pe[        R                  " SSS9   U R                  " XV/UQ70 UD6nSSS5        [        R
                  " W5      ) nU[        U5      -  nU[        U5      -  n[        R                  U R                  S5      n	U	b
  X" XV5      -  nUR                  (       d  U(       a  [        $ U$  [        R                  " USSUS9  [        R                  " X5      n
[        R                  " U
R                  UR                  SS9(       a  Xz-  nUR!                  [#        X5      5      nXl        ['        U[(        5      (       a  UR+                  U5        U$ ['        U[(        5      (       a  UR+                  U5        U$ ! , (       d  f       GN`= f! [         a     Nf = f)	r  r  r  Nr   r  r  safe)r  )rX   r  r  r   r  rm  rY   r  r'  r   rw   r  r   can_castr  r  ri  rc  rn  r  r   r  )r|  rS  r   r  r  r  r  rU  r   r  	masked_dar  s               r   r  !_DomainedBinaryOperation.__call__  sm    AJ
R[[(;VVB4T4V4F < ^^F##	WQZ	WQZ!!$&&$/Avv	IIfa;q-I{{9??FLL&I#
 $7$=>a%%&&q)  ;''&&q)G <;2  		s   FA F- 
F*-
F:9F:)r  r  r  r  r  r  s   @r   r  r    s    (	-( (r   r                ?gz8g      gg?c                    [         nU R                  bm  / nU R                   HD  nU R                  U   n[        U5      S:X  a  US   U4nUR	                  XB" US   U5      45        MF     [
        R                  " U5      nOaU R                  (       aN  [        U R                  5      nU" U R                  S   U5      US'   [
        R                  " [        U5      5      nOUnX`:X  a  U nU$ )z=Private function allowing recursion in _replace_dtype_fields.r   r   r   )
_replace_dtype_fields_recursiver  fieldsr<  r"   r  r  r  rs  r  )r  primitive_dtype_recursedescrr  field	new_dtypes          r   r  r  0  s    .H {{KKDLL&E5zQb	4(LL$q? CDE   HHUO	 
U^^$ENN1-?aHHU5\*	 $	 	r   c                 p    [         R                  " U 5      n [         R                  " U5      n[        X5      $ )z
Construct a dtype description list from a given dtype.

Returns a new dtype object, with all fields and subtypes in the given type
recursively replaced with `primitive_dtype`.

Arguments are coerced to dtypes first.
)r  r  r  )r  r  s     r   _replace_dtype_fieldsr  P  s*     HHUOEhh/O*5BBr   c                 "    [        U [        5      $ )a  
Construct a dtype description list from a given dtype.

Returns a new dtype object, with the type of all fields in `ndtype` to a
boolean type. Field names are not altered.

Parameters
----------
ndtype : dtype
    The dtype to convert.

Returns
-------
result : dtype
    A dtype that looks like `ndtype`, the type of all fields is boolean.

Examples
--------
>>> import numpy as np
>>> import numpy.ma as ma
>>> dtype = np.dtype({'names':['foo', 'bar'],
...                   'formats':[np.float32, np.int64]})
>>> dtype
dtype([('foo', '<f4'), ('bar', '<i8')])
>>> ma.make_mask_descr(dtype)
dtype([('foo', '|b1'), ('bar', '|b1')])
>>> ma.make_mask_descr(np.float32)
dtype('bool')

)r  r   )rN  s    r   rt   rt   ^  s    > !22r   c                 $    [        U S[        5      $ )av  
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 as np
>>> import numpy.ma as ma
>>> a = ma.masked_equal([[1,2],[3,4]], 2)
>>> a
masked_array(
  data=[[1, --],
        [3, 4]],
  mask=[[False,  True],
        [False, False]],
  fill_value=2)
>>> ma.getmask(a)
array([[False,  True],
       [False, False]])

Equivalently use the `MaskedArray` `mask` attribute.

>>> a.mask
array([[False,  True],
       [False, False]])

Result when mask == `nomask`

>>> b = ma.masked_array([[1,2],[3,4]])
>>> b
masked_array(
  data=[[1, 2],
        [3, 4]],
  mask=False,
  fill_value=999999)
>>> ma.nomask
False
>>> ma.getmask(b) == ma.nomask
True
>>> b.mask == ma.nomask
True

rn  )getattrr   )rS  s    r   rY   rY     s    r 1gv&&r   c                     [        U 5      nU[        L a+  [        [        R                  " U 5      [        U SS5      5      nU$ )a  
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 as np
>>> import numpy.ma as ma
>>> a = ma.masked_equal([[1,2],[3,4]], 2)
>>> a
masked_array(
  data=[[1, --],
        [3, 4]],
  mask=[[False,  True],
        [False, False]],
  fill_value=2)
>>> ma.getmaskarray(a)
array([[False,  True],
       [False, False]])

Result when mask == ``nomask``

>>> b = ma.masked_array([[1,2],[3,4]])
>>> b
masked_array(
  data=[[1, 2],
        [3, 4]],
  mask=False,
  fill_value=999999)
>>> ma.getmaskarray(b)
array([[False, False],
       [False, False]])

r  N)rY   r   ru   r  r   r  )r   rl  s     r   rZ   rZ     s7    ` 3<Dv~bhhsmWS'4-HIKr   c                 \     U R                   R                  [        L $ ! [         a     gf = f)ax  
Return True if m is a valid, standard mask.

This function does not check the contents of the input, only that the
type is MaskType. In particular, this function returns False if the
mask has a flexible dtype.

Parameters
----------
m : array_like
    Array to test.

Returns
-------
result : bool
    True if `m.dtype.type` is MaskType, False otherwise.

See Also
--------
ma.isMaskedArray : Test whether input is an instance of MaskedArray.

Examples
--------
>>> import numpy as np
>>> import numpy.ma as ma
>>> m = ma.masked_equal([0, 1, 0, 2, 3], 0)
>>> m
masked_array(data=[--, 1, --, 2, 3],
             mask=[ True, False,  True, False, False],
       fill_value=0)
>>> ma.is_mask(m)
False
>>> ma.is_mask(m.mask)
True

Input must be an ndarray (or have similar attributes)
for it to be considered a valid mask.

>>> m = [False, True, False]
>>> ma.is_mask(m)
False
>>> m = np.array([False, True, False])
>>> m
array([False,  True, False])
>>> ma.is_mask(m)
True

Arrays with complex dtypes don't return True.

>>> dtype = np.dtype({'names':['monty', 'pithon'],
...                   'formats':[bool, bool]})
>>> dtype
dtype([('monty', '|b1'), ('pithon', '|b1')])
>>> m = np.array([(True, False), (False, True), (True, False)],
...              dtype=dtype)
>>> m
array([( True, False), (False,  True), ( True, False)],
      dtype=[('monty', '?'), ('pithon', '?')])
>>> ma.is_mask(m)
False

F)r  r/  r   rh  r   s    r   rf   rf     s-    ~ww||x'' s    
++c                 j    U R                   R                  c  U R                  5       (       d  [        $ U $ )z%
Shrink a mask to nomask if possible
)r  r  r!   r   r  s    r   _shrink_maskr  :  s&     	ww}}QUUWWr   Fc                 z   U [         L a  [         $ [        U5      n[        U [        5      (       aN  U R                  R
                  (       a3  U[        R                  :X  a  [        R                  " U R                  US9$ U(       d  SOSn[        R                  " [        U S5      XSS9nU(       a  [        U5      nU$ )a  
Create a boolean mask from an array.

Return `m` as a boolean mask, creating a copy if necessary or requested.
The function can accept any sequence that is convertible to integers,
or ``nomask``.  Does not require that contents must be 0s and 1s, values
of 0 are interpreted as False, everything else as True.

Parameters
----------
m : array_like
    Potential mask.
copy : bool, optional
    Whether to return a copy of `m` (True) or `m` itself (False).
shrink : bool, optional
    Whether to shrink `m` to ``nomask`` if all its values are False.
dtype : dtype, optional
    Data-type of the output mask. By default, the output mask has a
    dtype of MaskType (bool). If the dtype is flexible, each field has
    a boolean dtype. This is ignored when `m` is ``nomask``, in which
    case ``nomask`` is always returned.

Returns
-------
result : ndarray
    A boolean mask derived from `m`.

Examples
--------
>>> import numpy as np
>>> import numpy.ma as ma
>>> m = [True, False, True, True]
>>> ma.make_mask(m)
array([ True, False,  True,  True])
>>> m = [1, 0, 1, 1]
>>> ma.make_mask(m)
array([ True, False,  True,  True])
>>> m = [1, 0, 2, -3]
>>> ma.make_mask(m)
array([ True, False,  True,  True])

Effect of the `shrink` parameter.

>>> m = np.zeros(4)
>>> m
array([0., 0., 0., 0.])
>>> ma.make_mask(m)
False
>>> ma.make_mask(m, shrink=False)
array([False, False, False, False])

Using a flexible `dtype`.

>>> m = [1, 0, 1, 1]
>>> n = [0, 1, 0, 0]
>>> arr = []
>>> for man, mouse in zip(m, n):
...     arr.append((man, mouse))
>>> arr
[(1, 0), (0, 1), (1, 0), (1, 0)]
>>> dtype = np.dtype({'names':['man', 'mouse'],
...                   'formats':[np.int64, np.int64]})
>>> arr = np.array(arr, dtype=dtype)
>>> arr
array([(1, 0), (0, 1), (1, 0), (1, 0)],
      dtype=[('man', '<i8'), ('mouse', '<i8')])
>>> ma.make_mask(arr, dtype=dtype)
array([(True, False), (False, True), (True, False), (True, False)],
      dtype=[('man', '|b1'), ('mouse', '|b1')])

r  NT)r=   r  rf  )r   rt   r  r   r  r  r  boolr   r   r   rN   r  )r   r=   shrinkr  rU  s        r   rs   rs   D  s    P 	F{ E"E !W!''..Ubgg5Ewwqwwe,, 4DXXfQoDTJFf%Mr   c                 ~    Uc  [         R                  " U [        S9nU$ [         R                  " U [        U5      S9nU$ )a  
Return a boolean mask of the given shape, filled with False.

This function returns a boolean ndarray with all entries False, that can
be used in common mask manipulations. If a complex dtype is specified, the
type of each field is converted to a boolean type.

Parameters
----------
newshape : tuple
    A tuple indicating the shape of the mask.
dtype : {None, dtype}, optional
    If None, use a MaskType instance. Otherwise, use a new datatype with
    the same fields as `dtype`, converted to boolean types.

Returns
-------
result : ndarray
    An ndarray of appropriate shape and dtype, filled with False.

See Also
--------
make_mask : Create a boolean mask from an array.
make_mask_descr : Construct a dtype description list from a given dtype.

Examples
--------
>>> import numpy as np
>>> import numpy.ma as ma
>>> ma.make_mask_none((3,))
array([False, False, False])

Defining a more complex dtype.

>>> dtype = np.dtype({'names':['foo', 'bar'],
...                   'formats':[np.float32, np.int64]})
>>> dtype
dtype([('foo', '<f4'), ('bar', '<i8')])
>>> ma.make_mask_none((3,), dtype=dtype)
array([(False, False), (False, False), (False, False)],
      dtype=[('foo', '|b1'), ('bar', '|b1')])

r  )r  r   r   rt   )newshaper  rU  s      r   ru   ru     s=    X }((3 M (/%*@AMr   c                     U R                   R                  nU HM  nX   nUR                   R                  b  [        XQU   X$   5        M1  [        R                  " XQU   X$   5        MO     g r  )r  r  _recursive_mask_orr  rq   )m1m2newmaskr  r  current1s         r   r  r    sV    HHNNE8>>+xD7=AX$x? r   c                 6   U [         L d  U SL a  [        US[        5      n[        XX4S9$ U[         L d  USL a  [        U S[        5      n[        XX4S9$ XL a$  [	        U 5      (       a  U(       a  [        U 5      $ U $ [        U SS5      [        USS5      peXV:w  a  [        SU< SU< S35      eUR                  bC  [        R                  " [        R                  " X5      R                  U5      n[        XU5        U$ [        [        R                  " X5      X#S9$ )	a4  
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
--------
>>> import numpy as np
>>> m1 = np.ma.make_mask([0, 1, 1, 0])
>>> m2 = np.ma.make_mask([1, 0, 0, 0])
>>> np.ma.mask_or(m1, m2)
array([ True,  True,  True, False])

Fr  )r=   r  r  NzIncompatible dtypes 'z'<>''r=   r  )r   r  r   rs   rf   r  rI  r  r  rI   	broadcastr   r  r  rq   )r  r  r=   r  r  dtype1dtype2r  s           r   rv   rv     s    L 	f"+GX.vCC
f"+GX.vCC	xGBKK#)|B1r1GT2GB4NVVVLMM||((2<</55v>27+U%%b-DHHr   c                    ^ S nU4S jm[         R                  " U 5      n T" U" U 5      5      n[         R                  " [        U5      [        S9$ )a  
Returns a completely flattened version of the mask, where nested fields
are collapsed.

Parameters
----------
mask : array_like
    Input array, which will be interpreted as booleans.

Returns
-------
flattened_mask : ndarray of bools
    The flattened input.

Examples
--------
>>> import numpy as np
>>> mask = np.array([0, 0, 1])
>>> np.ma.flatten_mask(mask)
array([False, False,  True])

>>> mask = np.array([(0, 0), (0, 1)], dtype=[('a', bool), ('b', bool)])
>>> np.ma.flatten_mask(mask)
array([False, False, False,  True])

>>> mdtype = [('a', bool), ('b', [('ba', bool), ('bb', bool)])]
>>> mask = np.array([(0, (0, 0)), (0, (0, 1))], dtype=mdtype)
>>> np.ma.flatten_mask(mask)
array([False, False, False, False, False,  True])

c                 ~    U R                   R                  nUb  U Vs/ s H  n[        X   5      PM     sn$ U $ s  snf )zCFlatten the mask and returns a (maybe nested) sequence of booleans.)r  r  rP   )rl  mnamesr  s      r   	_flatmaskflatten_mask.<locals>._flatmask6  s>    !!9?@L,@@K As   :c              3      >#     U  H*  n[        US5      (       a  T" U5       Sh  vN   M&  Uv   M,     g N! [         a    U v    gf = f7f)z.Generates a flattened version of the sequence.__iter__N)r   r   )sequenceelement_flatsequences     r   r0  #flatten_mask.<locals>._flatsequence>  sM     	#7J//,W555!M	 $5  	N	s1   A!8 68 A8 A	AA		Ar  )r  r0   r   rs  r  )rl  r*  	flattenedr0  s      @r   rP   rP     sA    B	 ::dDio.I88DO400r   c                 z    U[         R                  L a  0 OSU0nU [        La  U R                  " SSU0UD6$ [        $ )z:Check whether there are masked values along the given axiskeepdimsr  r   )r  r
   r   r   )rl  r  r4  r  s       r   _check_mask_axisr5  N  s=    r{{*RX0FF6xx,T,V,,Mr   c                    [        U SS9n[        R                  " XSS9nUR                  UR                  pTU(       a  XE:w  a  [	        SU< SU< S35      e[        US5      (       a!  [        X1R                  5      n[        U5      nO[        nUR                  U5      n[        U5      Ul        U(       dB  [        US5      (       a1  [        U5      [        L a  UR                  R                  5       Ul        U$ )	a
  
Mask an array where a condition is met.

Return `a` as an array masked where `condition` is True.
Any masked values of `a` or `condition` are also masked in the output.

Parameters
----------
condition : array_like
    Masking condition.  When `condition` tests floating point values for
    equality, consider using ``masked_values`` instead.
a : array_like
    Array to mask.
copy : bool
    If True (default) make a copy of `a` in the result.  If False modify
    `a` in place and return a view.

Returns
-------
result : MaskedArray
    The result of masking `a` where `condition` is True.

See Also
--------
masked_values : Mask using floating point equality.
masked_equal : Mask where equal to a given value.
masked_not_equal : Mask where *not* equal to a given value.
masked_less_equal : Mask where less than or equal to a given value.
masked_greater_equal : Mask where greater than or equal to a given value.
masked_less : Mask where less than a given value.
masked_greater : Mask where greater than a given value.
masked_inside : Mask inside a given interval.
masked_outside : Mask outside a given interval.
masked_invalid : Mask invalid values (NaNs or infs).

Examples
--------
>>> import numpy as np
>>> import numpy.ma as ma
>>> a = np.arange(4)
>>> a
array([0, 1, 2, 3])
>>> ma.masked_where(a <= 2, a)
masked_array(data=[--, --, --, 3],
             mask=[ True,  True,  True, False],
       fill_value=999999)

Mask array `b` conditional on `a`.

>>> b = ['a', 'b', 'c', 'd']
>>> ma.masked_where(a == 2, b)
masked_array(data=['a', 'b', --, 'd'],
             mask=[False, False,  True, False],
       fill_value='N/A',
            dtype='<U1')

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)

Fr  Tre  z<Inconsistent shape between the condition and the input (got z and )rn  )rs   r  r   r   
IndexErrorr   rv   rn  r/  r   ri  r  rl  rY   r   )	conditionrS  r=   condcshapeashaperb  rU  s           r   r   r   Z  s    J Yu-D
T*A

AGGV&"/5v? @ 	@q'tWW%1gVVC[Ft$FK GAw''GAJ&,@,,##%Mr   c                 (    [        [        X5      XS9$ )a  
Mask an array where greater than a given value.

This function is a shortcut to ``masked_where``, with
`condition` = (x > value).

See Also
--------
masked_where : Mask where a condition is met.

Examples
--------
>>> import numpy as np
>>> import numpy.ma as ma
>>> a = np.arange(4)
>>> a
array([0, 1, 2, 3])
>>> ma.masked_greater(a, 2)
masked_array(data=[0, 1, 2, --],
             mask=[False, False, False,  True],
       fill_value=999999)

r  )r   r[   r  valuer=   s      r   rz   rz     s    0 )188r   c                 (    [        [        X5      XS9$ )a  
Mask an array where greater than or equal to a given value.

This function is a shortcut to ``masked_where``, with
`condition` = (x >= value).

See Also
--------
masked_where : Mask where a condition is met.

Examples
--------
>>> import numpy as np
>>> import numpy.ma as ma
>>> a = np.arange(4)
>>> a
array([0, 1, 2, 3])
>>> ma.masked_greater_equal(a, 2)
masked_array(data=[0, 1, --, --],
             mask=[False, False,  True,  True],
       fill_value=999999)

r  )r   r\   r?  s      r   r{   r{     s    0 a/>>r   c                 (    [        [        X5      XS9$ )a  
Mask an array where less than a given value.

This function is a shortcut to ``masked_where``, with
`condition` = (x < value).

See Also
--------
masked_where : Mask where a condition is met.

Examples
--------
>>> import numpy as np
>>> import numpy.ma as ma
>>> a = np.arange(4)
>>> a
array([0, 1, 2, 3])
>>> ma.masked_less(a, 2)
masked_array(data=[--, --, 2, 3],
             mask=[ True,  True, False, False],
       fill_value=999999)

r  )r   rj   r?  s      r   r~   r~     s    0 Q55r   c                 (    [        [        X5      XS9$ )a  
Mask an array where less than or equal to a given value.

This function is a shortcut to ``masked_where``, with
`condition` = (x <= value).

See Also
--------
masked_where : Mask where a condition is met.

Examples
--------
>>> import numpy as np
>>> import numpy.ma as ma
>>> a = np.arange(4)
>>> a
array([0, 1, 2, 3])
>>> ma.masked_less_equal(a, 2)
masked_array(data=[--, --, --, 3],
             mask=[ True,  True,  True, False],
       fill_value=999999)

r  )r   rk   r?  s      r   r   r   &  s    0 
1,a;;r   c                 (    [        [        X5      XS9$ )a  
Mask an array where *not* equal to a given value.

This function is a shortcut to ``masked_where``, with
`condition` = (x != value).

See Also
--------
masked_where : Mask where a condition is met.

Examples
--------
>>> import numpy as np
>>> import numpy.ma as ma
>>> a = np.arange(4)
>>> a
array([0, 1, 2, 3])
>>> ma.masked_not_equal(a, 2)
masked_array(data=[--, --, 2, --],
             mask=[ True,  True, False,  True],
       fill_value=999999)

r  )r   r   r?  s      r   r   r   A  s    0 	!+Q::r   c                 8    [        [        X5      XS9nXl        U$ )al  
Mask an array where equal to a given value.

Return a MaskedArray, masked where the data in array `x` are
equal to `value`. The fill_value of the returned MaskedArray
is set to `value`.

For floating point arrays, consider using ``masked_values(x, value)``.

See Also
--------
masked_where : Mask where a condition is met.
masked_values : Mask using floating point equality.

Examples
--------
>>> import numpy as np
>>> import numpy.ma as ma
>>> a = np.arange(4)
>>> a
array([0, 1, 2, 3])
>>> ma.masked_equal(a, 2)
masked_array(data=[0, 1, --, 3],
             mask=[False, False,  True, False],
       fill_value=2)

r  )r   rK   rM  )r  r@  r=   outputs       r   ry   ry   \  s    8 %/18FMr   c                 L    X!:  a  X!p![        U 5      nXA:  XB:*  -  n[        XPUS9$ )aJ  
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 as np
>>> 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  rN   r   r  v1v2r=   xfr:  s         r   r|   r|   }  s3    D 
wR	Bbh'I	400r   c                 L    X!:  a  X!p![        U 5      nXA:  XB:  -  n[        XPUS9$ )aG  
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 as np
>>> 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  rH  rI  s         r   r   r     s3    D 
wR	BRW%I	400r   c                    [        U 5      (       a.  [        R                  " U R                  U5      nU R                  nO1[        R                  " [
        R                  " U 5      U5      n[        n[        U[        XCS95      n[        XX!S9$ )a   
Mask the array `x` where the data are exactly equal to value.

This function is similar to `masked_values`, but only suitable
for object arrays: for floating point, use `masked_values` instead.

Parameters
----------
x : array_like
    Array to mask
value : object
    Comparison value
copy : {True, False}, optional
    Whether to return a copy of `x`.
shrink : {True, False}, optional
    Whether to collapse a mask full of False to nomask

Returns
-------
result : MaskedArray
    The result of masking `x` where equal to `value`.

See Also
--------
masked_where : Mask where a condition is met.
masked_equal : Mask where equal to a given value (integers).
masked_values : Mask using floating point equality.

Examples
--------
>>> import numpy as np
>>> import numpy.ma as ma
>>> food = np.array(['green_eggs', 'ham'], dtype=object)
>>> # don't eat spoiled food
>>> eat = ma.masked_object(food, 'green_eggs')
>>> eat
masked_array(data=[--, 'ham'],
             mask=[ True, False],
       fill_value='green_eggs',
            dtype=object)
>>> # plain ol` ham is boring
>>> fresh_food = np.array(['cheese', 'ham', 'pineapple'], dtype=object)
>>> eat = ma.masked_object(fresh_food, 'green_eggs')
>>> eat
masked_array(data=['cheese', 'ham', 'pineapple'],
             mask=False,
       fill_value='green_eggs',
            dtype=object)

Note that `mask` is set to ``nomask`` if possible.

>>> eat
masked_array(data=['cheese', 'ham', 'pineapple'],
             mask=False,
       fill_value='green_eggs',
            dtype=object)

r7  rl  r=   rM  )re   r  rK   rg  rn  r  r0   r   rv   rs   rx   )r  r@  r=   r  r:  rl  s         r   r   r     sh    v QKK/	wwKK

1u5	49<=D4BBr   c                    [        X5      n[        R                  " UR                  [        R                  5      (       a  [        R
                  " XaX2S9nO[        R                  " Xa5      n[        XgXAS9nU(       a  UR                  5         U$ )aL  
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 as np
>>> import numpy.ma as ma
>>> x = np.array([1, 1.1, 2, 1.1, 3])
>>> ma.masked_values(x, 1.1)
masked_array(data=[1.0, --, 2.0, --, 3.0],
             mask=[False,  True, False,  True, False],
       fill_value=1.1)

Note that `mask` is set to ``nomask`` if possible.

>>> ma.masked_values(x, 2.1)
masked_array(data=[1. , 1.1, 2. , 1.1, 3. ],
             mask=False,
       fill_value=2.1)

Unlike `masked_equal`, `masked_values` can perform approximate equalities.

>>> ma.masked_values(x, 2.1, atol=1e-1)
masked_array(data=[1.0, 1.1, --, 1.1, 3.0],
             mask=[False, False,  True, False, False],
       fill_value=2.1)

)atolrtolrO  )
rN   r  
issubdtyper  floatingiscloser  rK   rx   shrink_mask)	r  r@  rR  rQ  r=   r  xnewrl  rets	            r   r   r   	  sd    | !D	}}TZZ--zz$D<{{4'
tT
DCJr   c                     [         R                  " U SSS9n [        [         R                  " U 5      ) XS9nUR                  [
        L a%  [        UR                  UR                  5      Ul        U$ )a  
Mask an array where invalid values occur (NaNs or infs).

This function is a shortcut to ``masked_where``, with
`condition` = ~(np.isfinite(a)). Any pre-existing mask is conserved.
Only applies to arrays with a dtype where NaNs or infs make sense
(i.e. floating point types), but accepts any array_like object.

See Also
--------
masked_where : Mask where a condition is met.

Examples
--------
>>> import numpy as np
>>> import numpy.ma as ma
>>> a = np.arange(5, dtype=float)
>>> a[2] = np.nan
>>> a[3] = np.inf
>>> a
array([ 0.,  1., nan, inf,  4.])
>>> ma.masked_invalid(a)
masked_array(data=[0.0, 1.0, --, --, 4.0],
             mask=[False, False,  True,  True, False],
       fill_value=1e+20)

NTre  r  )	r  r   r   rm  rn  r   ru   r   r  )rS  r=   ress      r   r}   r}   ]	  sV    8 	T*A
Q(!
7C yyF"399cii8	Jr   c                   D    \ rS rSrSrS rS rS rS rSS jr	S r
\
rS	rg
)_MaskedPrintOptioni	  zF
Handle the string used to represent missing data in a masked array.

c                     Xl         SU l        g)z)
Create the masked_print_option object.

TN_display_enabled)r|  displays     r   r}  _MaskedPrintOption.__init__	  s    
  r   c                     U R                   $ )z1
Display the string to print for masked values.

r_  r  s    r   ra  _MaskedPrintOption.display	      
 }}r   c                     Xl         g)z-
Set the string to print for masked values.

Nrd  )r|  r   s     r   set_display_MaskedPrintOption.set_display	  s	    
 r   c                     U R                   $ )z+
Is the use of the display value enabled?

r`  r  s    r   enabled_MaskedPrintOption.enabled	  rf  r   c                     Xl         g)z'
Set the enabling shrink to `shrink`.

Nrk  )r|  r  s     r   enable_MaskedPrintOption.enable	  s	    
 r   c                 ,    [        U R                  5      $ r  )r(  r_  r  s    r   r  _MaskedPrintOption.__str__	  s    4==!!r   r^  Nr  )r   r   r   r   r   r}  ra  rh  rl  ro  r  __repr__r   r   r   r   r\  r\  	  s,    
" Hr   r\  z--c                     U R                   R                  nUb  U H  nX   nX   n[        XVU5        M     g[        R                  " XUS9  g)z[
Puts printoptions in result where mask is True.

Private function allowing for recursion

Nr  )r  r  _recursive_printoptionr  r  )rU  rl  printoptr  r  curdatacurmasks          r   ru  ru  	  sS     LLEDlGjG"7X>   			&$/
r   z        masked_%(name)s(data =
         %(data)s,
        %(nlen)s        mask =
         %(mask)s,
        %(nlen)s  fill_value = %(fill)s)
        z        masked_%(name)s(data =
         %(data)s,
        %(nlen)s        mask =
         %(mask)s,
        %(nlen)s  fill_value = %(fill)s,
        %(nlen)s       dtype = %(dtype)s)
        z        masked_%(name)s(data = %(data)s,
        %(nlen)s        mask = %(mask)s,
        %(nlen)s  fill_value = %(fill)s)
        z        masked_%(name)s(data = %(data)s,
        %(nlen)s        mask = %(mask)s,
        %(nlen)s  fill_value = %(fill)s,
        %(nlen)s       dtype = %(dtype)s)
        )long_stdlong_flx	short_std	short_flxc                     U R                   R                  nU HK  nX   nUR                   R                  b  [        XQU   X$   5        M1  [        R                  " XRU   X   S9  MM     g)z*
Recursively fill `a` with `fill_value`.

Nr  )r  r  _recursive_filledr  r  )rS  rl  rM  r  r  currents         r   r~  r~  	  sX    
 GGMME'==*gDz:3CDIIg$/tzB r   c                 0  ^ U4S jm[         R                  " U 5      n U R                  nU R                  5       n [	        U [
        5      (       a  [         R                  " U R                   Vs/ s H"  n[        T" UR                  5       5      5      PM$     sn5      nUR                  [
        5      n[         R                  " [        U 5       Vs/ s H"  n[        T" UR                  5       5      5      PM$     sn5      Ul        OD[         R                  " U  Vs/ s H"  n[        T" UR                  5       5      5      PM$     sn5      n[        U5      S:  a/  [        UR                  5      nXS'   [        T" U5      5      Ul        U$ s  snf s  snf s  snf )a  
Flatten a structured array.

The data type of the output is chosen such that it can represent all of the
(nested) fields.

Parameters
----------
a : structured array

Returns
-------
output : masked array or ndarray
    A flattened masked array if the input is a masked array, otherwise a
    standard ndarray.

Examples
--------
>>> import numpy as np
>>> ndtype = [('a', int), ('b', float)]
>>> a = np.array([(1, 1), (2, 2)], dtype=ndtype)
>>> np.ma.flatten_structured_array(a)
array([[1., 1.],
       [2., 2.]])

c              3      >#    [        U 5       H*  n[        US5      (       a  T" U5       Sh  vN   M&  Uv   M,     g N7f)z+
Flattens a compound of nested iterables.

r-  N)iterr   )iterableelmflatten_sequences     r   r  2flatten_structured_array.<locals>.flatten_sequence
  s9     
 >CsJ''+C000		 "0s   +A >A r   r   )r  r/   r   r   r  r   r   rg  r  r?  ri  rZ   rn  r<  rs  )rS  inishaper  outr  r  s        @r   rQ   rQ   	  s1   8	 	aAwwH		A![!!hh177K7a.qvvx897KLhh{#HH'3A8'6! $$4QVVX$>?'68 9	 hh1E1a.qvvx891EF
8}q		?*845	J L8 Fs   -)F	)F)Fc                    ^ ^ U U4S jn[        [        T S5      =(       d    [        [        T S5      nUb  UR                  Ul        T Ul        U$ )a  
Return a class method wrapper around a basic array method.

Creates a class method which returns a masked array, where the new
``_data`` array is the output of the corresponding basic method called
on the original ``_data``.

If `onmask` is True, the new mask is the output of the method called
on the initial mask. Otherwise, the new mask is just a reference
to the initial mask.

Parameters
----------
funcname : str
    Name of the function to apply on data.
onmask : bool
    Whether the mask must be processed also (True) or left
    alone (False). Default is True. Make available as `_onmask`
    attribute.

Returns
-------
method : instancemethod
    Class method wrapper of the specified basic array method.

c                 "  > [        U R                  T5      " U0 UD6nUR                  [        U 5      5      nUR	                  U 5        U R
                  nT(       d  UR                  U5        U$ U[        La  [        UT5      " U0 UD6Ul        U$ r  )r  rg  ri  r/  r  rn  __setmask__r   )r|  r  paramsrU  rl  funcnameonmasks        r   wrapped_method$_arraymethod.<locals>.wrapped_methodN
  s    X.??T$Z(D!zzt$  "42DCFCFLr   N)r  r   r  r   r   )r  r  r  methdocs   ``  r   _arraymethodr  3
  sF    6
 gx.M'"h2MG!(&Nr   c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
MaskedIteratori`
  a=  
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
--------
>>> import numpy as np
>>> x = np.ma.array(arange(6).reshape(2, 3))
>>> fl = x.flat
>>> type(fl)
<class 'numpy.ma.MaskedIterator'>
>>> for item in fl:
...     print(item)
...
0
1
2
3
4
5

Extracting more than a single element b indexing the `MaskedIterator`
returns a masked array:

>>> fl[2:4]
masked_array(data = [2 3],
             mask = False,
       fill_value = 999999)

c                     Xl         UR                  R                  U l        UR                  [
        L a  S U l        g UR                  R                  U l        g r  )r  rg  flatdataiterrn  r   maskiter)r|  r  s     r   r}  MaskedIterator.__init__
  s8    88v DMHHMMDMr   c                     U $ r  r   r  s    r   r-  MaskedIterator.__iter__
      r   c                    U R                   R                  U5      R                  [        U R                  5      5      nU R
                  b  U R
                  R                  U5      n[        U[        5      (       a  UR                  Ul        X2l	        U$ [        U[        R                  5      (       a  [        X#U R                  R                  S9$ U(       a  [        $ U$ )Nrl  hardmask)r  __getitem__ri  r/  r  r  r  r   r   rn  r  rH  r   	_hardmaskrw   )r|  indxrU  rn  s       r   r  MaskedIterator.__getitem__
  s    **4055d477mD==$MM--d3E%))$ll$
 	 E277++V$'':K:KLLr   c                     [        U5      U R                  U'   U R                  b  [        U5      U R                  U'   g g r  )rX   r  r  rZ   )r|  indexr@  s      r   __setitem__MaskedIterator.__setitem__
  s6    &u~e==$#/#6DMM%  %r   c                    [        U R                  5      nU R                  b_  [        U R                  5      n[        U[        R
                  5      (       a  [        XU R                  R                  S9$ U(       a  [        $ U$ )z
Return the next value, or raise StopIteration.

Examples
--------
>>> import numpy as np
>>> x = np.ma.array([3, 2], mask=[0, 1])
>>> fl = x.flat
>>> next(fl)
3
>>> next(fl)
masked
>>> next(fl)
Traceback (most recent call last):
  ...
StopIteration

r  )
nextr  r  r  r  rH  r   r  r  rw   )r|  r  r   s      r   __next__MaskedIterator.__next__
  s_    & ==$T]]#A!RWW%%Q1B1BCCr   )r  r  r  N)r   r   r   r   r   r}  r-  r  r  r  r   r   r   r   r  r  `
  s!    .`*7
r   r  znumpy.mac                     ^  \ rS rSrSrSr\rSr\	r
SrSrS\SSSS	SSSSS4S
 jrS rS rSS jrSS jrS r\R(                  " SSS9S 5       r\U 4S j5       r\R0                  U 4S j5       r\U 4S j5       r\R0                  U 4S j5       rSS jr\r\S 5       r\R0                  S 5       r\S 5       r\R0                  S 5       rS rS r\S 5       r S r!\S  5       r"S! r#\S" 5       r$S# r%\" \%S$9r&\" \%S$9r'\S% 5       r(\(R0                  S& 5       r(\S' 5       r)\)R0                  SS( j5       r)\)RT                  r+\)RX                  r-SS) jr.S* r/SS+ jr0S, r1S- r2S. r3S/ r4S0 r5S1 r6S2 r7S3 r8S4 r9S5 r:S6 r;S7 r<S8 r=S9 r>S: r?S; r@S< rAS= rBS> rCS? rDS@ rESA rFSB rGSC rHSD rISE rJSF rKSG rLSH rMSI rNSJ rOSK rPSL rQ\SM 5       rR\RRT                  rS\SN 5       rT\TRT                  rUS\R                  4SO jrWSSP jrXSQ rYSSR jrZSSS jr[ST r\SU r]SS\R                  4SV jr^SS\R                  4SW jr_SX r`SU 4SY jjra\	R                  R                  \al        SSZ jrbSSS\R                  4S[ jrcSS\ jrdSSS\R                  4S] jre\erfSS^ jrgSSS\R                  4U 4S_ jjrhSS` jriSSSS	\R                  \R                  4U 4Sa jjrj\R                  R                  \jl        SSSS	\R                  \R                  4Sb jrkSSc jrl\R                  SSSS4SSd.Se jjrmS\R                  Sf.Sg jjrnS\R                  Sf.Sh jjro  SSSd.Si jjrpSSS\R                  4Sj jrqSSS\R                  4Sk jrrSSl jrsU 4Sm jrtU 4Sn jruSSo jrv\w" Sp5      rx\w" Sq5      ry\w" Sr5      rz\w" Ss5      r{\w" St5      r|\w" Su5      r}\" Sv S$9r~\w" Sw5      r\Sx 5       rSSy jrSSz jrSS{ jrSS| jrS} r\rU 4S~ jrU 4S jrS rSS jrSrU =r$ )r   i
  a=  
An array class with possibly masked values.

Masked values of True exclude the corresponding element from any
computation.

Construction::

  x = MaskedArray(data, mask=nomask, dtype=None, copy=False, subok=True,
                  ndmin=0, fill_value=None, keep_mask=True, hard_mask=None,
                  shrink=True, order=None)

Parameters
----------
data : array_like
    Input data.
mask : sequence, optional
    Mask. Must be convertible to an array of booleans with the same
    shape as `data`. True indicates a masked (i.e. invalid) data.
dtype : dtype, optional
    Data type of the output.
    If `dtype` is None, the type of the data argument (``data.dtype``)
    is used. If `dtype` is not None and different from ``data.dtype``,
    a copy is performed.
copy : bool, optional
    Whether to copy the input data (True), or to use a reference instead.
    Default is False.
subok : bool, optional
    Whether to return a subclass of `MaskedArray` if possible (True) or a
    plain `MaskedArray`. Default is True.
ndmin : int, optional
    Minimum number of dimensions. Default is 0.
fill_value : scalar, optional
    Value used to fill in the masked values when necessary.
    If None, a default based on the data-type is used.
keep_mask : bool, optional
    Whether to combine `mask` with the mask of the input data, if any
    (True), or to use only `mask` for the output (False). Default is True.
hard_mask : bool, optional
    Whether to use a hard mask or not. With a hard mask, masked values
    cannot be unmasked. Default is False.
shrink : bool, optional
    Whether to force compression of an empty mask. Default is True.
order : {'C', 'F', 'A'}, optional
    Specify the order of the array.  If order is 'C', then the array
    will be in C-contiguous order (last-index varies the fastest).
    If order is 'F', then the returned array will be in
    Fortran-contiguous order (first-index varies the fastest).
    If order is 'A' (default), then the returned array may be
    in any order (either C-, Fortran-contiguous, or even discontiguous),
    unless a copy is required, in which case it will be C-contiguous.

Examples
--------
>>> import numpy as np

The ``mask`` can be initialized with an array of boolean values
with the same shape as ``data``.

>>> data = np.arange(6).reshape((2, 3))
>>> np.ma.MaskedArray(data, mask=[[False, True, False],
...                               [False, False, True]])
masked_array(
  data=[[0, --, 2],
        [3, 4, --]],
  mask=[[False,  True, False],
        [False, False,  True]],
  fill_value=999999)

Alternatively, the ``mask`` can be initialized to homogeneous boolean
array with the same shape as ``data`` by passing in a scalar
boolean value:

>>> np.ma.MaskedArray(data, mask=False)
masked_array(
  data=[[0, 1, 2],
        [3, 4, 5]],
  mask=[[False, False, False],
        [False, False, False]],
  fill_value=999999)

>>> np.ma.MaskedArray(data, mask=True)
masked_array(
  data=[[--, --, --],
        [--, --, --]],
  mask=[[ True,  True,  True],
        [ True,  True,  True]],
  fill_value=999999,
  dtype=int64)

.. note::
    The recommended practice for initializing ``mask`` with a scalar
    boolean value is to use ``True``/``False`` rather than
    ``np.True_``/``np.False_``. The reason is :attr:`nomask`
    is represented internally as ``np.False_``.

    >>> np.False_ is np.ma.nomask
    True

   Fd   i  NTr   c                 	  ^ U(       d  SOSn[         R                  " XUUSUS9n[        US[        U5      5      n[	        U[
        5      (       a  UR                  UR                  :w  a  Sn[	        X5      (       a=  U(       a6  [	        U[        5      (       d!  [        R                  " U[        U5      5      nO[        R                  " X5      n[        US5      (       a&  [	        U[        5      (       d  UR                  Ul        [        UR                  5      nU[        L Ga[  U(       d:  U
(       a  [        Ul        GO[         R                  " UR                  US9Ul        GO[	        U[         ["        45      (       az   [         R                  " U Vs/ s H*  n[%        [         R&                  " XR                  S95      PM,     snUS9nU[,        :X  a"  UR/                  5       (       a  X,l        SUl        GO/U(       + Ul        U(       ap  UR                  R3                  5       Ul        [5        U5      [        La?  UR                  R                  UR                  :w  a  UR                  UR                  l        GOUc  SnUSL a*  U[,        :X  a   [         R6                  " UR                  US9nOEUSL a*  U[,        :X  a   [         R                  " UR                  US9nO [         R                  " X$US9nUR                  UR                  :w  az  UR:                  UR:                  nnUS	:X  a!  [         R<                  " X,R                  5      nO9UU:X  a!  [         R>                  " X,R                  5      nOS
n[A        UUU4-  5      eSnUR                  [        L a  X,l        U(       + Ul        OwU(       d  X,l        U(       + Ul        O]UR                  RB                  b  U4S jmT" UR                  U5        O%[         RD                  " X,R                  5      Ul        SUl        Uc  [        USS5      nUb  [G        X|R                  5      Ul$        U	c  [        USS5      Ul%        OXl%        Xl&        U$ s  snf ! [(        [*        4 a
    [        n GNf = f! [*         aF    [         R                  " U Vs/ s H  n[!        U/[9        U5      -  5      PM     Os  snf snUS9n GNf = f)zz
Create a new masked array from scratch.

Notes
-----
A masked array can also be created by taking a .view(MaskedArray).

NT)r  r=   orderrf  ndmin
_baseclassrn  r  Fr=   r  r   z?Mask and data not compatible: data size is %i, mask size is %i.c                    > U R                   R                   H/  nX   X   pCUR                   R                  b
  T" X45        M+  X4-  nM1     g)z'do a|=b on each field of a, recursivelyN)r  r  )rS  r   r  afbf_recursive_ors        r   r  *MaskedArray.__new__.<locals>._recursive_or  s=    (),-GQWR#%88>>#=$1"$9$&HB )6r   _fill_valuer  )'r  r   r  r/  r  r   r   r]  r   ri  r   rn  rt   r  r   r   r  rs  rZ   r/   rI  r   r   r!   _sharedmaskr=   rY   r   r<  r   r   r   r   r  rq   rP  r  r  r  )rb  rj  rl  r  r=   rf  r  rM  	keep_mask	hard_maskr  r  rg  r  mdtyper   ndnmmsgr  s                      @r   __new__MaskedArray.__new__?  s     tT$D?T<e=
dK((djjEKK.GD
 d  U:dN3S3SLLT
3ELL,E 4!!*T7*C*C**EK !-6> "(EK #%((5;;f"EEKD5$-00"88"&("&Q &bmmA[[&IJ"&(/57D h&DHHJJ"&K(-E%(,H!"'++"2"2"4EKt}F2  ::++tzz9/3zzDJJ, |t|( 2wwu{{&96X#5xx6:288D6BD zzU[[(!JJ		R799T;;7D2X::dKK8D-C#C2r(N33{{f$"(,H! "&K,0E%{{((4- &ekk48&(mmD++&F(-E%  }d;J! 1*kk JE%dK?EO'O%w("I. "!D"L ! 288t$Lt!UA3V+<%=t$L*02D2sB   R  1Q;R  $R ;R   RRS-;"S
S-,S-c                     [        U[        5      (       a  [        U5      nO[        n0 nUR                  [	        US0 5      5        UR                  [	        US0 5      5        [        U[
        5      (       d  UR                  [	        US0 5      5        [        [	        USS5      [	        USS5      [	        USS5      [	        US	S5      [	        US
U5      UUS9nU R                  R                  U5        U R                  R                  U5        g)z)
Copies some attributes of obj to self.

_optinfo	_basedict__dict__r  Nr  Fr  _isfieldr  )r  r  r  r  r  r  r  )r  r   r/  updater  r   r[  r  )r|  r   r  r  _dicts        r   r  MaskedArray._update_from  s    
 c7##cJ JZ45["56#{++OOGCR89mT!B&sK?!(mU!C%c:u= '\: F&') 	U#X&r   c                    U R                  U5        [        U[        5      (       a  UR                  R                  b  [        U5      nO[        U5      nU[        La  UR                  S   S   U R                  S   S   :w  a  U R                  UR                  :X  a  UR                  nO[        U R                  5      nU R                  R                  (       a  SnO U R                  R                  (       a  SnOSnUR                  X45      nOUR                  5       nO[        nX l        U R                  [        La   U R                   U R                  l        U R(                  b&  [+        U R(                  U R                  5      U l        gU R                  R                  b  [+        SU R                  5      U l        gg! ["         a    [        U l         N~[$        [&        4 a     Nf = f)z
Finalizes the masked array.

Nrj  r   CFK)r  r  r   r  r  rZ   rY   r   __array_interface__rt   flagsc_contiguousf_contiguousastyperi  rn  r   rI  r   rh  r  rP  )r|  r   rn  _mask_dtyper  s        r   __array_finalize__MaskedArray.__array_finalize__  s    	#8 c7## yy*$S) V#(?(?(G(J//7:); ::*"'++K"1$**"=K::**EZZ,,EE[8 

E
::V##'::

  '01A1A4::NDZZ)0tzzBD *  $#
~. s   G G,G,+G,c           	      j   XL a  UnO+UR                  [        U 5      5      nUR                  U 5        UGb6  UR                  R	                  5       Ul        Uu  pVnUSUR
                   n[        R                  " [        U V	s/ s H  n	[        U	5      PM     sn	5      n
[        R                  U5      nUb  [        R                  " SSS9   U" U6 R                  [        SS9n[!        US5      nSSS5        WR#                  5       (       a2   [$        U   S   n[        R,                  " XMUS9  U
[.        L a  Un
OX-  n
X@La  UR0                  S	:X  a  U
(       a  [2        $ Xl        SUl        U$ s  sn	f ! , (       d  f       N= f! [&         a    [$        U   n N[(         a    U R*                  n Nf = f)
zZ
Special hook for ufuncs.

Wraps the numpy array and sets the mask according to context.

Nr  r  Fr  Tr   r  r   )ri  r/  r  rn  r=   nin	functoolsr  rv   rZ   r  r'  r  r  r  r  rN   r!   r  r   r0  rM  r  r   r   rw   r  )r|  r   contextreturn_scalarrU  funcr  out_i
input_argsargr   r  r  rM  s                 r   __array_wrap__MaskedArray.__array_wrap__G  s    ;FXXd4j)F%!<<,,.FL 'DitxxJ  
*S
<+<
*STA!%%d+F![[(C 
+224e2DAq$A D 55775%0%6r%:
 IIf: F{ U !fllb&8Q %*"Q +T
 DC % 7%0%6
# 5%)__
5s*   E/
$E4F 4
FF2F21F2c                 *   Uc1  Uc  [         R                  " U 5      nOw[         R                  " X5      nO`UcF   [        U[         5      (       a  [         R                  " X5      nSnO.[         R                  " X5      nO[         R                  " XU5      n[	        U5      [
        La  UR                  R                  5       Ul        [        USS5      b  Uc  Uc   U$ SUl         U$ X4l	        U$ ! [         a    [         R                  " X5      n N|f = f)a  
Return a view of the MaskedArray data.

Parameters
----------
dtype : data-type or ndarray sub-class, optional
    Data-type descriptor of the returned view, e.g., float32 or int16.
    The default, None, results in the view having the same data-type
    as `a`. As with ``ndarray.view``, dtype can also be specified as
    an ndarray sub-class, which then specifies the type of the
    returned object (this is equivalent to setting the ``type``
    parameter).
type : Python type, optional
    Type of the returned view, either ndarray or a subclass.  The
    default None results in type preservation.
fill_value : scalar, optional
    The value to use for invalid entries (None by default).
    If None, then this argument is inferred from the passed `dtype`, or
    in its absence the original array, as discussed in the notes below.

See Also
--------
numpy.ndarray.view : Equivalent method on ndarray object.

Notes
-----

``a.view()`` is used two different ways:

``a.view(some_dtype)`` or ``a.view(dtype=some_dtype)`` constructs a view
of the array's memory with a different data-type.  This can cause a
reinterpretation of the bytes of memory.

``a.view(ndarray_subclass)`` or ``a.view(type=ndarray_subclass)`` just
returns an instance of `ndarray_subclass` that looks at the same array
(same shape, dtype, etc.)  This does not cause a reinterpretation of the
memory.

If `fill_value` is not specified, but `dtype` is specified (and is not
an ndarray sub-class), the `fill_value` of the MaskedArray will be
reset. If neither `fill_value` nor `dtype` are specified (or if
`dtype` is an ndarray sub-class), then the fill value is preserved.
Finally, if `fill_value` is specified, but `dtype` is not, the fill
value is set to the specified value.

For ``a.view(some_dtype)``, if ``some_dtype`` has a different number of
bytes per entry than the previous dtype (for example, converting a
regular array to a structured array), then the behavior of the view
cannot be predicted just from the superficial appearance of ``a`` (shown
by ``print(a)``). It also depends on exactly how ``a`` is stored in
memory. Therefore if ``a`` is C-ordered versus fortran-ordered, versus
defined as a slice or transpose, etc., the view may give different
results.
Nr  )
r   ri  r^  r   rY   r   rn  r  r  rM  )r|  r  r/  rM  rF  s        r   ri  MaskedArray.view  s    p =| d+ d1\3eW--$\\$6F E$\\$6F \\$t4F
 6?&(!<<,,.FL 6=$/;!=
  *.F&  %/!)  3 d23s   -C/ 'C/ / DDc                     U R                   U   nU R                  nS nS nU[        La  X1   nU" U5      nO0[        nU" U R                   U5      nUc  U" [        U 5      U   5      nU(       a  [	        U[
        R                  5      (       a  [        X&U R                  S9$ U R                  R                  [
        R                  L a;  [	        U[
        R                  5      (       a  U[        La  U(       a
  [        USS9$ U$ U(       a  [        $ U$ UR                  [        U 5      5      nUR!                  U 5        [#        U5      (       Ga  U R$                  b  U R$                  U   Ul        [	        UR$                  [
        R                  5      (       d  ['        S5      eUR$                  R(                  S:  a  UR$                  UR$                  R*                  S   :H  R-                  5       (       d+  [.        R0                  " SU< S	UR$                  S   < S
3SS9  UR$                  R*                  SS R3                  SS9Ul        SUl        U[        La!  [7        XbR8                  5      Ul        SUl        U$ )zQ
x.__getitem__(y) <==> x[y]

Return the item described by i, as a masked array.

c                 @    [        U [        R                  5      (       + $ r  )r  r  r   r  s    r   
_is_scalar+MaskedArray.__getitem__.<locals>._is_scalar  s    !!RZZ000r   c                    [        U[        R                  5      (       d  gU R                  R                  [        R
                  L a  U R                  UR                  La  g g[	        U 5      R                  [        R                  :X  a  gg)z|
Return whether `elem` is a scalar result of indexing `arr`, or None
if undecidable without promoting nomask to a full mask
TFN)r  r  r   r  r/  object_r  )r   elems     r   _scalar_heuristic2MaskedArray.__getitem__.<locals>._scalar_heuristic  sm     dBJJ// 2::-99DJJ.   /  c&&'*=*==r   r  Trl  zInternal NumPy error.r   z&Upon accessing multidimensional field zi, need to keep dimensionality of fill_value at 0. Discarding heterogeneous fill_value and setting all to r.     r   r   r  )rj  rn  r   rZ   r  r  rH  r   r  r  r/  r  r   rw   r   ri  r  rv  r  RuntimeErrorr   r  r   r   r   r   r  r   r   r  )r|  r  doutrn  r  r  moutscalar_expecteds           r   r  MaskedArray.__getitem__  s7    yy

	1	.  ;D(.O D/		4@O& #-\$-?-E"F $(( Tt~~FF **//RZZ/T2::..f$&t$77K !MK 99T$Z(Dd#+D11##/'+'7'7'=D$ &d&6&6

CC*+BCC '',,q0 $ 0 0 $ 0 0 5 5a 8!9:=#% @$MM H#'( +* +/*:*:1*=)@	!C
 ,-. ,0+;+;+@+@1+E+M+MST+M+U( $6!$T::6
#' r   r  )overro  c                    U [         L a  [        S5      eU R                  nU R                  n[	        U[
        5      (       aB  X#U'   U[        L a'  [        U R                  U R                  5      =U l        n[        U5      XA'   gUR                  nU[         L a\  U[        L a  [        U R                  U5      =o@l        UR                  b%  [        S/[        UR                  5      -  5      XA'   gSXA'   g[        USU5      n[        U5      nUR                  b+  U[        L a"  [        S/[        UR                  5      -  5      nU[        L a.  XcU'   U[        La   [        U R                  U5      =o@l        XtU'   gU R                  (       dC  [	        U[         5      (       a$  [	        U[         5      (       d  XcUR"                  '   gXcU'   XtU'    g[%        US5      (       a2  UR                  [&        :X  a  U[(        R*                  " U5      -  nXcU'   gUR                  b  Sn[-        U5      e[/        XA   USS9n	U R                  U   n
U
R0                  S	:  a  [2        R4                  " XU	) S
9  OU	[        L a  Un
XU'   XU'   g)zk
x.__setitem__(i, y) <==> x[i]=y

Set item described by index. If value is masked, masks those
locations.

z Cannot alter the masked element.NTrg  Fr  z,Flexible 'hard' masks are not yet supported.r  r   r  )rw   r   rg  rn  r  r(  r   ru   r   r  rY   r  r  r<  r  r  rx   rj  r   r   r  rp   NotImplementedErrorrv   r   r  r  )r|  r  r@  rg  rn  _dtypedvalmvalrO  mindxdindxs              r   r  MaskedArray.__setitem__^  s@    6>>??



dC  $K%3DJJ

%KK
U!%.EKF?%3DJJ%GG
||'#TFS->$>?  # ugu-u~<<#%3v||#445DF?$K6!%3DJJ%GG
"d0 	/ 4.."5,77#'dii & 	# #d"d  	 T7##x)?%++E22D$K 	 ||'H)'22EKD9EJJt$EzzA~		%eV4&$K$Kr   c                    > [         TU ]  $ r  )r  r  r|  r  s    r   r  MaskedArray.dtype      w}r   c                 :  > [         [        [        U 5      ]  R	                  X5        U R
                  [        LaK  U R
                  R                  [        U5      [        5      U l         U R                  U R
                  l
        g g ! [        [        4 a     g f = fr  )r  r   r/  r  __set__rn  r   ri  rt   r   r   rh  r   )r|  r  r  s     r   r  r     sv    k4:,44TA::V#)?IDJ#'::

  $ #I. s   *B BBc                    > [         TU ]  $ r  )r  r   r  s    r   r   MaskedArray.shape  r  r   c                    > [         [        [        U 5      ]  R	                  X5        [        U 5      [        La  U R                  U R                  l        g g r  )r  r   r/  r   r  rY   r   rn  )r|  r   r  s     r   r   r    s?    k4:,44TA 4=&#zzDJJ 'r   c                    U R                   nU R                  nU[        L a  SnU[        L a&  U[        L a  g[	        U R
                  U5      =o@l        UR                  c^  U R                  (       a  XA-  nGOx[        U[        [        [        R                  [        R                  45      (       a  XS'   GO9Xl        GO1UR                   n[        R                  " U5      nUR                   (       df  UR                   R"                  S:X  a:  [        R$                  " ['        UR)                  5       /[+        U5      -  5      US9nO3UR-                  U5      nO! U(       d  SOSn[        R$                  " XUS9nU R                  (       a"  UR                   H  nXG==   X   -  ss'   M     OD[        U[        [        [        R                  [        R                  45      (       a  XS'   OXl        UR
                  (       a  U R
                  Ul        g! [.         aE    [        R$                  " U Vs/ s H  n['        U/[+        U5      -  5      PM     Os  snf snUS9n Nf = f)z
Set the mask.

TN.r   r  r  )r  rn  rw   r   ru   r   r  r  r  intr  r  r  numberr  r0   r   r%  r   r  r?  r<  r  r   )r|  rl  r=   idtypecurrent_maskr  r   ns           r   r  MaskedArray.__setmask__  s   
 zz6>D6! v~(6tzz6(JJL:<< ~~$ D3rww		"BCC$(S! %)! "''F::d#D99::??c)88E499;-#f+*E$F*02D  ;;v.D2'+4D88D6BD ~~A Otw.O &
 D3rww		"BCC$(S! %)!!%L% ! 288t$Lt!UA3V+<%=t$L*02D2s    H I!0"I
I! I!c                 6    U R                   R                  5       $ )zCurrent mask. )rn  ri  r  s    r   rl  MaskedArray.mask	  s     zz  r   c                 &    U R                  U5        g r  )r  )r|  r@  s     r   rl  r    s    r   c                     U R                   R                  [        5      nUR                  R                  c  U$ [
        R                  " [        U5      SS9$ )a  
Get or set the mask of the array if it has no named fields. For
structured arrays, returns a ndarray of booleans where entries are
``True`` if **all** the fields are masked, ``False`` otherwise:

>>> x = np.ma.array([(1, 1), (2, 2), (3, 3), (4, 4), (5, 5)],
...         mask=[(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)],
...        dtype=[('a', int), ('b', int)])
>>> x.recordmask
array([False, False,  True, False, False])
r   r  )rn  ri  r   r  r  r  r   rQ   )r|  rn  s     r   
recordmaskMaskedArray.recordmask  sB     

(;;$Lvv.u5B??r   c                     [        S5      e)Nz*Coming soon: setting the mask per records!r  )r|  rl  s     r   r  r  *  s    !"NOOr   c                     SU l         U $ )aM  
Force the mask to hard, preventing unmasking by assignment.

Whether the mask of a masked array is hard or soft is determined by
its `~ma.MaskedArray.hardmask` property. `harden_mask` sets
`~ma.MaskedArray.hardmask` to ``True`` (and returns the modified
self).

See Also
--------
ma.MaskedArray.hardmask
ma.MaskedArray.soften_mask

Tr  r  s    r   r]   MaskedArray.harden_mask.  s     r   c                     SU l         U $ )aV  
Force the mask to soft (default), allowing unmasking by assignment.

Whether the mask of a masked array is hard or soft is determined by
its `~ma.MaskedArray.hardmask` property. `soften_mask` sets
`~ma.MaskedArray.hardmask` to ``False`` (and returns the modified
self).

See Also
--------
ma.MaskedArray.hardmask
ma.MaskedArray.harden_mask

Fr  r  s    r   r   MaskedArray.soften_mask@  s     r   c                     U R                   $ )a  
Specifies whether values can be unmasked through assignments.

By default, assigning definite values to masked array entries will
unmask them.  When `hardmask` is ``True``, the mask will not change
through assignments.

See Also
--------
ma.MaskedArray.harden_mask
ma.MaskedArray.soften_mask

Examples
--------
>>> import numpy as np
>>> x = np.arange(10)
>>> m = np.ma.masked_array(x, x>5)
>>> assert not m.hardmask

Since `m` has a soft mask, assigning an element value unmasks that
element:

>>> m[8] = 42
>>> m
masked_array(data=[0, 1, 2, 3, 4, 5, --, --, 42, --],
             mask=[False, False, False, False, False, False,
                   True, True, False, True],
       fill_value=999999)

After hardening, the mask is not affected by assignments:

>>> hardened = np.ma.harden_mask(m)
>>> assert m.hardmask and hardened is m
>>> m[:] = 23
>>> m
masked_array(data=[23, 23, 23, 23, 23, 23, --, --, 23, --],
             mask=[False, False, False, False, False, False,
                   True, True, False, True],
       fill_value=999999)

r  r  s    r   r  MaskedArray.hardmaskR  s    V ~~r   c                 t    U R                   (       a&  U R                  R                  5       U l        SU l         U $ )a  
Copy the mask and set the `sharedmask` flag to ``False``.

Whether the mask is shared between masked arrays can be seen from
the `sharedmask` property. `unshare_mask` ensures the mask is not
shared. A copy of the mask is only made if it was shared.

See Also
--------
sharedmask

F)r  rn  r=   r  s    r   unshare_maskMaskedArray.unshare_mask  s,     *DJ$Dr   c                     U R                   $ )z&Share status of the mask (read-only). )r  r  s    r   
sharedmaskMaskedArray.sharedmask  s     r   c                 :    [        U R                  5      U l        U $ )ah  
Reduce a mask to nomask when possible.

Parameters
----------
None

Returns
-------
None

Examples
--------
>>> import numpy as np
>>> x = np.ma.array([[1,2 ], [3, 4]], mask=[0]*4)
>>> x.mask
array([[False, False],
       [False, False]])
>>> x.shrink_mask()
masked_array(
  data=[[1, 2],
        [3, 4]],
  mask=False,
  fill_value=999999)
>>> x.mask
False

)r  rn  r  s    r   rV  MaskedArray.shrink_mask  s    : "$**-
r   c                     U R                   $ )z*Class of the underlying data (read-only). )r  r  s    r   	baseclassMaskedArray.baseclass  s     r   c                 B    [         R                  " X R                  5      $ )aZ  
Returns the underlying data, as a view of the masked array.

If the underlying data is a subclass of :class:`numpy.ndarray`, it is
returned as such.

>>> x = np.ma.array(np.matrix([[1, 2], [3, 4]]), mask=[[0, 1], [1, 0]])
>>> x.data
matrix([[1, 2],
        [3, 4]])

The type of the data can be accessed through the :attr:`baseclass`
attribute.
)r   ri  r  r  s    r   	_get_dataMaskedArray._get_data  s     ||D//22r   )fgetc                     [        U 5      $ )zEReturn a flat iterator, or set a flattened version of self to value. )r  r  s    r   r  MaskedArray.flat  s     d##r   c                 ,    U R                  5       nXS S & g r  )r   )r|  r@  ys      r   r  r-    s    JJL!r   c                     U R                   c  [        SU R                  5      U l         [        U R                   [        5      (       a  U R                   S   $ U R                   $ )aR  
The filling value of the masked array is a scalar. When setting, None
will set to a default based on the data type.

Examples
--------
>>> import numpy as np
>>> for dt in [np.int32, np.int64, np.float64, np.complex128]:
...     np.ma.array([0, 1], dtype=dt).get_fill_value()
...
np.int64(999999)
np.int64(999999)
np.float64(1e+20)
np.complex128(1e+20+0j)

>>> x = np.ma.array([0, 1.], fill_value=-np.inf)
>>> x.fill_value
np.float64(-inf)
>>> x.fill_value = np.pi
>>> x.fill_value
np.float64(3.1415926535897931)

Reset to default:

>>> x.fill_value = None
>>> x.fill_value
np.float64(1e+20)

Nr   )r  rP  r  r  r   r  s    r   rM  MaskedArray.fill_value  sU    > #0tzzBD d&&00##B''r   c                     [        XR                  5      nUR                  S:X  d  [        R                  " S[
        SS9  U R                  nUc  X l        g X#S'   g )Nr   zNon-scalar arrays for the fill value are deprecated. Use arrays with scalar values instead. The filled function still supports any array as `fill_value`.r  r   r   )rP  r  r   r   r   DeprecationWarningr  )r|  r@  r  r  s       r   rM  r1    sV    "5**5{{aMM< #q	2 &&% %Or   c                 d   U R                   nU[        L a  U R                  $ Uc  U R                  nO[	        XR
                  5      nU [        L a  [        R                  " U5      $ UR
                  R                  b3  U R                  R                  S5      n[        X0R                   U5        U$ UR                  5       (       d  U R                  $ U R                  R                  S5      n [        R                  " X1US9  U$ ! [        [        4 a?    [!        U["        S9nUR%                  ["        5      n[        R&                  " X$U45      n U$ [(         aT    U R                  R*                  (       a  e U(       a!  [        R,                  " XR
                  S9n U$ U R                  n U$ f = f)a  
Return a copy of self, with masked values filled with a given value.
**However**, if there are no masked values to fill, self will be
returned instead as an ndarray.

Parameters
----------
fill_value : array_like, optional
    The value to use for invalid entries. Can be scalar or non-scalar.
    If non-scalar, the resulting ndarray must be broadcastable over
    input array. Default is None, in which case, the `fill_value`
    attribute of the array is used instead.

Returns
-------
filled_array : ndarray
    A copy of ``self`` with invalid entries replaced by *fill_value*
    (be it the function argument or the attribute of ``self``), or
    ``self`` itself as an ndarray if there are no invalid entries to
    be replaced.

Notes
-----
The result is **not** a MaskedArray!

Examples
--------
>>> import numpy as np
>>> x = np.ma.array([1,2,3,4,5], mask=[0,0,1,0,1], fill_value=-999)
>>> x.filled()
array([   1,    2, -999,    4, -999])
>>> x.filled(fill_value=1000)
array([   1,    2, 1000,    4, 1000])
>>> type(x.filled())
<class 'numpy.ndarray'>

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', '<i8'), ('f1', '<i8')])
r  r  r  )rn  r   rg  rM  rP  r  r   r  r/   r  r=   r~  r!   r  r   rh  narrayrJ  r  r5   r9  r   r   )r|  rM  r   rU  r  s        r   rN   MaskedArray.filled  s[   \ JJ;::J*:zzBJ##==,,77==$ZZ__S)Ffjj*=& % ::ZZ__S)F(		&A6  ~. 7#Jf=
MM&)1*o6   (::##XXj

CF  "ZZF(s    -D AF/A
F/F/.F/c                     [         R                  " U R                  5      nU R                  [        LaC  UR                  [        R                  " [         R                  " U R                  5      5      5      nU$ )a  
Return all the non-masked data as a 1-D array.

Returns
-------
data : ndarray
    A new `ndarray` holding the non-masked data is returned.

Notes
-----
The result is **not** a MaskedArray!

Examples
--------
>>> import numpy as np
>>> x = np.ma.array(np.arange(5), mask=[0]*2 + [1]*3)
>>> x.compressed()
array([0, 1])
>>> type(x.compressed())
<class 'numpy.ndarray'>

N-D arrays are compressed to 1-D.

>>> arr = [[1, 2], [3, 4]]
>>> mask = [[1, 0], [0, 1]]
>>> x = np.ma.array(arr, mask=mask)
>>> x.compressed()
array([2, 3])

)r   r   rg  rn  r   r8   r  rp   )r|  rj  s     r   r9   MaskedArray.compressedk  sK    > }}TZZ(::V#==djj0I!JKDr   c                    U R                   U R                  pT[        R                  " U5      nUR	                  XUS9R                  [        U 5      5      nUR                  U 5        U[        La  UR	                  XS9Ul        U$ )a  
Return `a` where condition is ``True``.

If condition is a `~ma.MaskedArray`, missing values are considered
as ``False``.

Parameters
----------
condition : var
    Boolean 1-d array selecting which entries to return. If len(condition)
    is less than the size of a along the axis, then output is truncated
    to length of condition array.
axis : {None, int}, optional
    Axis along which the operation must be performed.
out : {None, ndarray}, optional
    Alternative output array in which to place the result. It must have
    the same shape as the expected output but the type will be cast if
    necessary.

Returns
-------
result : MaskedArray
    A :class:`~ma.MaskedArray` object.

Notes
-----
Please note the difference with :meth:`compressed` !
The output of :meth:`compress` has a mask, the output of
:meth:`compressed` does not.

Examples
--------
>>> import numpy as np
>>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
>>> x
masked_array(
  data=[[1, --, 3],
        [--, 5, --],
        [7, --, 9]],
  mask=[[False,  True, False],
        [ True, False,  True],
        [False,  True, False]],
  fill_value=999999)
>>> x.compress([1, 0, 1])
masked_array(data=[1, 3],
             mask=[False, False],
       fill_value=999999)

>>> x.compress([1, 0, 1], axis=1)
masked_array(
  data=[[1, 3],
        [--, --],
        [7, 9]],
  mask=[[False, False],
        [ True,  True],
        [False, False]],
  fill_value=999999)

r  r  r  )	rg  rn  r  r0   r8   ri  r/  r  r   )r|  r:  r  r  rg  rn  _news          r   r8   MaskedArray.compress  sr    z **djj JJy)	~~i~<AA$t*M$	=DJr   c                    [         R                  5       (       Ga1  U R                  nU[        L a  U R                  nU$ U R                  nU R
                  S:  a  U R                  OU R                  n[        U R
                  5       H  nUR                  U   U:  d  M  US-  n[        R                  " X6U* 4US9n[        R                  " US   US   4US9n[        R                  " XU* 4US9n[        R                  " US   US   4US9nM     [        U R                  S5      nUR                  U5      n[!        X![         5         U$ U R#                  U R$                  5      nU$ )zY
Replace masked values with masked_print_option, casting all innermost
dtypes to object.
r   r  r  r   r   )r   rl  rn  r   rg  r   _print_width_print_width_1dranger   r  r   r:   r  r  r  ru  rN   rM  )	r|  rl  rZ  rj  print_widthr  indr   rdtypes	            r   _insert_masked_print MaskedArray._insert_masked_print  s@   
 &&((::Dv~jj* 
% zz 59IIMt00$($8$8 !$)),Dzz$'+5)Q. hhtC4[tD!~~s1vs1v.>TJ hhtC4[tD!~~s1vs1v.>TJ - /tzz3?kk&)&s2EF 
 ++doo.C
r   c                 4    [        U R                  5       5      $ r  )r(  rD  r  s    r   r  MaskedArray.__str__  s    4,,.//r   c           
      ,  ^^ U R                   [        R                  L a  SnOU R                   R                  n[        R                  R
                  R                  5       S::  a  U R                  S:  n[        US[        U5      -  [        U 5      [        U R                  5      [        U R                  5      [        U R                  5      S9n[        U R                  R                  5      nSR!                  U(       a  SOSU(       a  S	OS
5      n["        U   U-  $ SU S3n[        R                  R
                  R%                  U R                  5      (       + =(       d6    [        R&                  " U R(                  5      =(       d    U R*                  S:H  n/ SQnU(       a  UR-                  S5        [.        R&                  " S U R0                  SS  5       5      n	Sn
U	(       aR  0 mUTUS   '   USS  H<  n[.        R2                  " U
[        XhS   -   5      [        U5      -
  5      nSU-  TU'   M>     SnOU Vs0 s H  oSU
-  _M
     snmUS-   n0 m[        R4                  " U R7                  5       STS   S-   SS9TS'   [        R4                  " U R                  STS   S-   SS9TS'   U R8                  c  U R                    U R8                  R                  R:                  S;   a\  U R                  R:                  U R8                  R                  R:                  :X  a$  [=        U R                  R?                  5       5      nOcU R8                  R                  U R                  :X  a*  U R                  [@        :X  d  [        U R                  5      nO[=        U R                  5      nUTS'   U(       a6  [        R                  R
                  RC                  U R                  5      TS'   SRE                  UU4S  jU 5       5      nXn-   S!-   $ s  snf )"z!
Literal string representation.

r   q   r    )r  nlenrj  rl  r  r  z{}_{}longshortflxr   masked_(r   )rj  rl  rM  r  c              3   *   #    U  H	  oS :H  v   M     g7f)r   Nr   )r  dims     r   r  'MaskedArray.__repr__.<locals>.<genexpr>%  s     !Fos(os   Nr   r  r   
z, rj  zdata=,)	separatorprefixsuffixrl  zmask=)r   r   rM  z,
c              3   V   >#    U  H  nS R                  TU   UTU   5      v   M      g7f)z{}{}={}N)format)r  kindentsreprss     r   r  rS  W  s2      
 WQZE!H55s   &)r8  )#r  r  r   r   _core
arrayprint_get_legacy_print_moder   r[  r<  r(  rn  rM  r  r  r  rZ  _legacy_print_templatesdtype_is_impliedr   rl  r   r"   rt  r   r   array2stringrD  r  r%  reprr?  rJ  dtype_short_reprr   )r|  r  is_long
parametersis_structuredkeyrW  dtype_neededkeys
is_one_row
min_indentr[  r  	fill_reprrU  r\  r]  s                  @@r   rs  MaskedArray.__repr__  sd   
 ??bjj(D??++D 885573>ii!mG3t9_Y_)$**oJ !!1!12M..!w&EC +3/*<<4&" ##44TZZ@@ FF499IIN 	 .KK  \\!Fdjj"o!FF
 
 G%GDG!"XLLSq'1A-BSV-KL 1W
  F 599Dq#
**D9Gd]F %%'6?W,	f
 JJ6?W,	f #OO""'':5JJOOt'7'7'='='B'BBT__1134I##tzz1$**:N DOO,IT__-I'lXX00AA$**ME'N  

 
 $$O :s   ?Pc                     [        U[        U 5      5      (       a  g[        USS5      nUSL a  [        USS5      nU R                  U:  $ US L $ )NF__array_ufunc____array_priority__i)r  r/  r  rr  )r|  otherarray_ufuncother_prioritys       r   _delegate_binopMaskedArray._delegate_binop]  s\     eT$Z((e%6>%$U,@(KN**^;; $&&r   c                    [        U5      nU R                  n[        XCSS9n[        U5      nUR                  R
                  b  U[        R                  [        R                  4;  a  [        $ [        R                  " X5      R                  n[        R                  " XSS9nXXl        UR                  U5      n	U[        R                   " SUR                  5      :H  nU[        R"                  L a!  [        R$                  " SUR                  5      nOU R&                  n	U" X5      n
[)        U
[        R*                  [*        45      (       a  U(       a  [,        $ U
$ U[.        La  U[        R                  [        R                  4;   a  [        R0                  " XR" XC5      U
5      n
UR                  U
R                  :w  a.  [        R                  " XZR                  5      R3                  5       nU
R5                  [7        U 5      5      n
U
R9                  U 5        XZl        U
R:                  b+   [=        U
R:                  [        R*                  5      nXl        U
$ ! [>        [@        4 a    [=        S[        R*                  5      n N4f = f)a  Compare 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.
Tr  Nrf  r   )!rY   rl  rv   rX   r  r  operatoreqneNotImplementedr  r$  r   broadcast_torn  rN   r   False_r   rj  r  r  rw   r   r   r=   ri  r/  r  r  rP  r   rI  )r|  rs  compareomasksmaskrl  odatabroadcast_shape
sbroadcastsdatacheckr  s               r   _comparisonMaskedArray._comparisonk  s    		u$/::' x{{HKK88%% !ll47==OdKJ#%%e,E BGGB

33D		!U[[1 IIE%ebggt_--!6,u,v8;;44
 wu'<eDzzU[[( t[[9>>@

4:&4  (8():):BGGD !%	 z* 8(rww78s   ,$I *JJc                 B    U R                  U[        R                  5      $ )a  Check 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.
)r  rz  r{  r|  rs  s     r   __eq__MaskedArray.__eq__       x{{33r   c                 B    U R                  U[        R                  5      $ )a  Check 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.
)r  rz  r|  r  s     r   __ne__MaskedArray.__ne__  r  r   c                 B    U R                  U[        R                  5      $ r  )r  rz  ler  s     r   __le__MaskedArray.__le__      x{{33r   c                 B    U R                  U[        R                  5      $ r  )r  rz  ltr  s     r   __lt__MaskedArray.__lt__  r  r   c                 B    U R                  U[        R                  5      $ r  )r  rz  ger  s     r   __ge__MaskedArray.__ge__  r  r   c                 B    U R                  U[        R                  5      $ r  )r  rz  gtr  s     r   __gt__MaskedArray.__gt__  r  r   c                 P    U R                  U5      (       a  [        $ [        X5      $ )z4
Add self to other, and return a new masked array.

)rv  r}  r   r  s     r   __add__MaskedArray.__add__  s&    
 &&!!4r   c                     [        X5      $ )z4
Add other to self, and return a new masked array.

)r   r  s     r   __radd__MaskedArray.__radd__  s     5r   c                 P    U R                  U5      (       a  [        $ [        X5      $ )z;
Subtract other from self, and return a new masked array.

)rv  r}  r   r  s     r   __sub__MaskedArray.__sub__  s&    
 &&!!$$r   c                     [        X5      $ )z;
Subtract self from other, and return a new masked array.

)r   r  s     r   __rsub__MaskedArray.__rsub__  s    
 $$r   c                 P    U R                  U5      (       a  [        $ [        X5      $ )z6Multiply self by other, and return a new masked array.)rv  r}  r   r  s     r   __mul__MaskedArray.__mul__  s$    &&!!$$r   c                     [        X5      $ )z9
Multiply other by self, and return a new masked array.

)r   r  s     r   __rmul__MaskedArray.__rmul__  s     $$r   c                 P    U R                  U5      (       a  [        $ [        X5      $ z9
Divide other into self, and return a new masked array.

)rv  r}  rH   r  s     r   __div__MaskedArray.__div__  s&    
 &&!!d""r   c                 P    U R                  U5      (       a  [        $ [        X5      $ r  )rv  r}  r   r  s     r   __truediv__MaskedArray.__truediv__  s&    
 &&!!4''r   c                     [        X5      $ z9
Divide self into other, and return a new masked array.

)r   r  s     r   __rtruediv__MaskedArray.__rtruediv__  s    
 5''r   c                 P    U R                  U5      (       a  [        $ [        X5      $ r  )rv  r}  rS   r  s     r   __floordiv__MaskedArray.__floordiv__&  s&    
 &&!!D((r   c                     [        X5      $ r  )rS   r  s     r   __rfloordiv__MaskedArray.__rfloordiv__/  s    
 E((r   c                 P    U R                  U5      (       a  [        $ [        X5      $ )zA
Raise self to the power other, masking the potential NaNs/Infs

)rv  r}  r   r  s     r   __pow__MaskedArray.__pow__6  s&    
 &&!!T!!r   c                     [        X5      $ )zA
Raise other to the power self, masking the potential NaNs/Infs

)r   r  s     r   __rpow__MaskedArray.__rpow__?  s    
 U!!r   c                    [        U5      nU R                  [        L aY  U[        LaO  UR                  5       (       a:  [	        U R
                  U R                  5      U l        U =R                  U-  sl        OU[        La  U =R                  U-  sl        [        U5      n[        R                  " U R                  UR                  R                  S5      U5      nU R                  R                  U5        U $ )z
Add other to self in-place.

r   )rY   rn  r   r!   ru   r   r  rX   r  r   r/  rg  __iadd__r|  rs  r   
other_datas       r   r  MaskedArray.__iadd__F  s    
 EN::15577+DJJ

C


a


a
U^
XXdjj**:*:*?*?*BJO


J'r   c                    [        U5      nU R                  [        L aY  U[        LaO  UR                  5       (       a:  [	        U R
                  U R                  5      U l        U =R                  U-  sl        OU[        La  U =R                  U-  sl        [        U5      n[        R                  " U R                  UR                  R                  S5      U5      nU R                  R                  U5        U $ )z%
Subtract other from self in-place.

r   )rY   rn  r   r!   ru   r   r  rX   r  r   r/  rg  __isub__r  s       r   r  MaskedArray.__isub__X      
 EN::15577+DJJ

C


a
f_JJ!OJU^
XXdjj**:*:*?*?*BJO


J'r   c                    [        U5      nU R                  [        L aY  U[        LaO  UR                  5       (       a:  [	        U R
                  U R                  5      U l        U =R                  U-  sl        OU[        La  U =R                  U-  sl        [        U5      n[        R                  " U R                  UR                  R                  S5      U5      nU R                  R                  U5        U $ )z#
Multiply self by other in-place.

r   )rY   rn  r   r!   ru   r   r  rX   r  r   r/  rg  __imul__r  s       r   r  MaskedArray.__imul__i  r  r   c                 "   [        U5      n[        5       R                  U R                  U5      n[	        U5      n[        XC5      nUR                  5       (       aI  [        [        R                     u  pg[        R                  " X2R                  R                  U5      U5      nU =R                  U-  sl        [        R                  " U R                  UR                  R                  S5      U5      nU R                  R                  U5        U $ )z!
Divide self by other in-place.

r   )rX   r  r  rg  rY   rv   r!   r  r  rH   r   r  r/  rn  __idiv__r|  rs  r  dom_mask
other_masknew_mask_rC  s           r   r  MaskedArray.__idiv__z  s    
 U^
$&//

JGU^
:0<<>>#BII.IQ..33D9:GJ

h
XXdjj**:*:*?*?*BJO


J'r   c                 "   [        U5      n[        5       R                  U R                  U5      n[	        U5      n[        XC5      nUR                  5       (       aI  [        [        R                     u  pg[        R                  " X2R                  R                  U5      U5      nU =R                  U-  sl        [        R                  " U R                  UR                  R                  S5      U5      nU R                  R                  U5        U $ )z'
Floor divide self by other in-place.

r   )rX   r  r  rg  rY   rv   r!   r  r  rS   r   r  r/  rn  __ifloordiv__r  s           r   r  MaskedArray.__ifloordiv__  s    
 U^
$&//

JGU^
:0<<>>#BOO4IQ..33D9:GJ

h
XXdjj**:*:*?*?*BJO


  ,r   c                 "   [        U5      n[        5       R                  U R                  U5      n[	        U5      n[        XC5      nUR                  5       (       aI  [        [        R                     u  pg[        R                  " X2R                  R                  U5      U5      nU =R                  U-  sl        [        R                  " U R                  UR                  R                  S5      U5      nU R                  R                  U5        U $ )z&
True divide self by other in-place.

r   )rX   r  r  rg  rY   rv   r!   r  r  r   r   r  r/  rn  __itruediv__r  s           r   r  MaskedArray.__itruediv__  s    
 U^
$&//

JGU^
:0<<>>#BNN3IQ..33D9:GJ

h
XXdjj**:*:*?*?*BJO



+r   c                    [        U5      n[        R                  " U R                  UR                  R                  S5      U5      n[        U5      n[        R                  " SSS9   U R                  R                  U5        SSS5        [        R                  " [        R                  " U R                  5      5      nUR                  5       (       aY  U R                  [        La  U =R                  U-  sl        OX@l        [        R                  " U R                  U R                  US9  [!        X45      n[!        U R                  U5      U l        U $ ! , (       d  f       N= f)z+
Raise self to the power other, in place.

r   r  r  Nr  )rX   r  r   rn  r  r/  rY   r  rg  __ipow__rp   rm  r!   r   r  rM  rv   )r|  rs  r  r  ro  r  s         r   r  MaskedArray.__ipow__  s    
 U^
XXdjj**:*:*?*?*BJO
U^
[[(;JJ
+ <..TZZ!89;;==zz'

g%
$
IIdjj$//A:/TZZ2
 <;s   'E
E#c                     U R                   S:  a  [        S5      eU R                  (       a%  [        R                  " SSS9  [
        R                  $ [        U R                  5       5      $ )z
Convert to float.

r   7Only length-1 arrays can be converted to Python scalarsz,Warning: converting a masked element to nan.r  r   )	r   r   rn  r   r   r  nanr  r?  r  s    r   	__float__MaskedArray.__float__  sR    
 99q= 0 1 1ZZMMHUVW66MTYY[!!r   c                     U R                   S:  a  [        S5      eU R                  (       a  [        S5      e[	        U R                  5       5      $ )z
Convert to int.

r   r  z.Cannot convert masked element to a Python int.)r   r   rn  r   r  r?  r  s    r   __int__MaskedArray.__int__  sE    
 99q= 0 1 1ZZLMM499;r   c                     U R                   R                  R                  [        U 5      5      nUR	                  U R
                  5        U$ )ai  
The imaginary part of the masked array.

This property is a view on the imaginary part of this `MaskedArray`.

See Also
--------
real

Examples
--------
>>> import numpy as np
>>> x = np.ma.array([1+1.j, -2j, 3.45+1.6j], mask=[False, True, False])
>>> x.imag
masked_array(data=[1.0, --, 1.6],
             mask=[False,  True, False],
       fill_value=1e+20)

)rg  imagri  r/  r  rn  r|  rU  s     r   r  MaskedArray.imag  7    * %%d4j14::&r   c                     U R                   R                  R                  [        U 5      5      nUR	                  U R
                  5        U$ )a`  
The real part of the masked array.

This property is a view on the real part of this `MaskedArray`.

See Also
--------
imag

Examples
--------
>>> import numpy as np
>>> x = np.ma.array([1+1.j, -2j, 3.45+1.6j], mask=[False, True, False])
>>> x.real
masked_array(data=[1.0, --, 3.45],
             mask=[False,  True, False],
       fill_value=1e+20)

)rg  realri  r/  r  rn  r  s     r   r  MaskedArray.real  r  r   c                    U[         R                  L a  0 OSU0nU R                  n[        U R                  [         R
                  5      (       aZ  U[        L a-  [         R                  " U R                  [         R                  S9nUR                  [        U R                  5      5      nU[        L GaZ  U R                  S:X  a.  US;  a'  [         R                  R                  XR                  S9egUc[  UR                  SS5      (       a8  [         R                   " U R"                  [         R$                  U R                  S9$ U R"                  $ ['        XR                  5      nSnU H  nX`R                  U   -  nM     UR                  SS5      (       a#  [)        U R                  5      nU H  n	SX'   M	     O0[+        U R                  5       V
Vs/ s H  u  pX;  d  M  UPM     nn
n[         R,                  " X[         R$                  S9$ U [.        L a  g	U) R0                  " SU[         R$                  S
.UD6$ s  snn
f )a  
Count the non-masked elements of the array along the given axis.

Parameters
----------
axis : None or int or tuple of ints, optional
    Axis or axes along which the count is performed.
    The default, None, performs the count over all
    the dimensions of the input array. `axis` may be negative, in
    which case it counts from the last to the first axis.
    If this is a tuple of ints, the count is performed on multiple
    axes, instead of a single axis or all the axes as before.
keepdims : bool, optional
    If this is set to True, the axes which are reduced are left
    in the result as dimensions with size one. With this option,
    the result will broadcast correctly against the array.

Returns
-------
result : ndarray or scalar
    An array with the same shape as the input array, with the specified
    axis removed. If the array is a 0-d array, or if `axis` is None, a
    scalar is returned.

See Also
--------
ma.count_masked : Count masked elements in array or along a given axis.

Examples
--------
>>> import numpy.ma as ma
>>> a = ma.arange(6).reshape((2, 3))
>>> a[1, :] = ma.masked
>>> a
masked_array(
  data=[[0, 1, 2],
        [--, --, --]],
  mask=[[False, False, False],
        [ True,  True,  True]],
  fill_value=999999)
>>> a.count()
3

When the `axis` keyword is specified an array of appropriate size is
returned.

>>> a.count(axis=0)
array([1, 1, 1])
>>> a.count(axis=1)
array([3, 0])

r4  r  r   Nr   )r  r   r   F)r  r  r   r  r  )r  r
   rn  r  rj  matrixr   r   r   r  ri  r/  
exceptions	AxisErrorr   r'  r   r   intpr   rs  	enumerater  rw   r   )r|  r  r4  r  r   axesitemsaxout_dimsrS  r  r  s               r   rA   MaskedArray.count  s   j  2;;.Z4JJJ dii++F{HHTZZrww7tDII'A; zzRy(--11t))1LL::j%0088DIIRWWDIINNyy 'ii8DEB'  zz*e,,

+A"#HK  +4DJJ*? .*?$! } *? . 778"'':: 6>xx;T;F;;.s   H;!H;c                    US;   a)  U R                   R                  R                  (       a  SOSn[        R                  " U R                   US9R                  [        U 5      5      nUR                  U 5        U R                  [        La?  [        R                  " U R                  US9R                  UR                  5      Ul        U$ [        Ul        U$ )a=  
Returns a 1D version of self, as a view.

Parameters
----------
order : {'C', 'F', 'A', 'K'}, optional
    The elements of `a` are read using this index order. 'C' means to
    index the elements in C-like order, with the last axis index
    changing fastest, back to the first axis index changing slowest.
    'F' means to index the elements in Fortran-like index order, with
    the first index changing fastest, and the last index changing
    slowest. Note that the 'C' and 'F' options take no account of the
    memory layout of the underlying array, and only refer to the order
    of axis indexing.  'A' means to read the elements in Fortran-like
    index order if `m` is Fortran *contiguous* in memory, C-like order
    otherwise.  'K' means to read the elements in the order they occur
    in memory, except for reversing the data when strides are negative.
    By default, 'C' index order is used.
    (Masked arrays currently use 'A' on the data when 'K' is passed.)

Returns
-------
MaskedArray
    Output view is of shape ``(self.size,)`` (or
    ``(np.ma.product(self.shape),)``).

Examples
--------
>>> import numpy as np
>>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
>>> x
masked_array(
  data=[[1, --, 3],
        [--, 5, --],
        [7, --, 9]],
  mask=[[False,  True, False],
        [ True, False,  True],
        [False,  True, False]],
  fill_value=999999)
>>> x.ravel()
masked_array(data=[1, --, 3, --, 5, --, 7, --, 9],
             mask=[False,  True, False,  True, False,  True, False,  True,
                   False],
       fill_value=999999)

kKaAr  r  r  )rg  r  fncr   r   ri  r/  r  rn  r   r   r   )r|  r  rs      r   r   MaskedArray.ravely  s    h F?::++//CSEMM$**E277T
C	t::V#mmDJJe<DDQWWMAG  AGr   c                 &   UR                  UR                  SS5      S9  U R                  R                  " U0 UD6R	                  [        U 5      5      nUR                  U 5        U R                  nU[        La  UR                  " U0 UD6Ul        U$ )a^  
Give a new shape to the array without changing its data.

Returns a masked array containing the same data, but with a new shape.
The result is a view on the original array; if this is not possible, a
ValueError is raised.

Parameters
----------
shape : int or tuple of ints
    The new shape should be compatible with the original shape. If an
    integer is supplied, then the result will be a 1-D array of that
    length.
order : {'C', 'F'}, optional
    Determines whether the array data should be viewed as in C
    (row-major) or FORTRAN (column-major) order.

Returns
-------
reshaped_array : array
    A new view on the array.

See Also
--------
reshape : Equivalent function in the masked array module.
numpy.ndarray.reshape : Equivalent method on ndarray object.
numpy.reshape : Equivalent function in the NumPy module.

Notes
-----
The reshaping operation cannot guarantee that a copy will not be made,
to modify the shape in place, use ``a.shape = s``

Examples
--------
>>> import numpy as np
>>> x = np.ma.array([[1,2],[3,4]], mask=[1,0,0,1])
>>> x
masked_array(
  data=[[--, 2],
        [3, --]],
  mask=[[ True, False],
        [False,  True]],
  fill_value=999999)
>>> x = x.reshape((4,1))
>>> x
masked_array(
  data=[[--],
        [2],
        [3],
        [--]],
  mask=[[ True],
        [False],
        [False],
        [ True]],
  fill_value=999999)

r  r  r  )	r  r'  rg  r   ri  r/  r  rn  r   )r|  r   r  rU  rl  s        r   r   MaskedArray.reshape  s    v 	FJJw45##Q1&166tDzBD!zzv<<5f5FLr   c                     Sn[        U5      e)a>  
.. warning::

    This method does nothing, except raise a ValueError exception. A
    masked array does not own its data and therefore cannot safely be
    resized in place. Use the `numpy.ma.resize` function instead.

This method is difficult to implement safely and may be deprecated in
future releases of NumPy.

zoA masked array does not own its data and therefore cannot be resized.
Use the numpy.ma.resize function instead.)rI  )r|  r  refcheckr  errmsgs        r   r   MaskedArray.resize  s    =   r   c                    U R                   (       a\  U R                  [        LaI  U R                  U   n[        USS9n[        USSS9nUR	                  UR
                  5        X)    nX$)    nU R                  R                  XUS9  U R                  [        L a  [        U5      [        L a  g[        U 5      n[        U5      [        L a  UR                  USUS9  OUR                  XR                  US9  [        USSS9nXPl        g)a  
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
--------
>>> import numpy as np
>>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
>>> x
masked_array(
  data=[[1, --, 3],
        [--, 5, --],
        [7, --, 9]],
  mask=[[False,  True, False],
        [ True, False,  True],
        [False,  True, False]],
  fill_value=999999)
>>> x.put([0,4,8],[10,20,30])
>>> x
masked_array(
  data=[[10, --, 3],
        [--, 20, --],
        [7, --, 30]],
  mask=[[False,  True, False],
        [ True, False,  True],
        [False,  True, False]],
  fill_value=999999)

>>> x.put(4,999)
>>> x
masked_array(
  data=[[10, --, 3],
        [--, 999, --],
        [7, --, 30]],
  mask=[[False,  True, False],
        [ True, False,  True],
        [False,  True, False]],
  fill_value=999999)

Nr  Tre  modeFr#  )r  rn  r   r5  r   r   rg  r   rY   rZ   rs   )r|  ra   valuesr  rl  r   s         r   r   MaskedArray.put  s    | >>djj6::g&DW40GFT:FMM'--(enGE]F

wT2 ::GFOv$=6?f$EE'5tE,EE'<<dE3aeD1
r   c                     U R                   [        L a%  U R                  R                  [	        [        5      4$ U R                  R                  U R                   R                  R                  4$ )a  
Return the addresses of the data and mask areas.

Parameters
----------
None

Examples
--------
>>> import numpy as np
>>> x = np.ma.array([1, 2, 3], mask=[0, 1, 1])
>>> x.ids()
(166670640, 166659832) # may vary

If the array has no mask, the address of `nomask` is returned. This address
is typically not close to the data in memory:

>>> x = np.ma.array([1, 2, 3])
>>> x.ids()
(166691080, 3083169284) # may vary

)rn  r   ctypesrj  idr  s    r   r`   MaskedArray.idsc  sN    . ::KK$$bj11  $**"3"3"8"899r   c                      U R                   S   $ )a  
Return a boolean indicating whether the data is contiguous.

Parameters
----------
None

Examples
--------
>>> import numpy as np
>>> x = np.ma.array([1, 2, 3])
>>> x.iscontiguous()
True

`iscontiguous` returns one of the flags of the masked array:

>>> x.flags
  C_CONTIGUOUS : True
  F_CONTIGUOUS : True
  OWNDATA : False
  WRITEABLE : True
  ALIGNED : True
  WRITEBACKIFCOPY : False


CONTIGUOUS)r  r  s    r   iscontiguousMaskedArray.iscontiguous~  s    4 zz,''r   c                 
   U[         R                  L a  0 OSU0n[        U R                  U40 UD6nUcn  U R	                  S5      R
                  " SSU0UD6R                  [        U 5      5      nUR                  (       a  UR                  U5        U$ U(       a  [        $ U$ U R	                  S5      R
                  " SXS.UD6  [        U[        5      (       a)  UR                  (       d  U(       a  UR                  U5        U$ )a  
Returns True if all elements evaluate to True.

The output array is masked where all the values along the given axis
are masked: if the output would have been a scalar and that all the
values are masked, then the output is `masked`.

Refer to `numpy.all` for full documentation.

See Also
--------
numpy.ndarray.all : corresponding function for ndarrays
numpy.all : equivalent function

Examples
--------
>>> import numpy as np
>>> np.ma.array([1,2,3]).all()
True
>>> a = np.ma.array([1,2,3], mask=True)
>>> (a.all() is np.ma.masked)
True

r4  Tr  r:  r   )r  r
   r5  rn  rN   r   ri  r/  r   r  rw   r  r   r|  r  r  r4  r  rl  r  s          r   r   MaskedArray.all  s    2  2;;.Z4J

D;F;;D!%%:4:6:??T
KAvvd# H HD;4;F;c;''xx4%
r   c                 
   U[         R                  L a  0 OSU0n[        U R                  U40 UD6nUcn  U R	                  S5      R
                  " SSU0UD6R                  [        U 5      5      nUR                  (       a  UR                  U5        U$ U(       a  [        nU$ U R	                  S5      R
                  " SXS.UD6  [        U[        5      (       a)  UR                  (       d  U(       a  UR                  U5        U$ )a  
Returns True if any of the elements of `a` evaluate to True.

Masked values are considered as False during computation.

Refer to `numpy.any` for full documentation.

See Also
--------
numpy.ndarray.any : corresponding function for ndarrays
numpy.any : equivalent function

r4  Fr  r:  r   )r  r
   r5  rn  rN   r!   ri  r/  r   r  rw   r  r   r   s          r   r!   MaskedArray.any  s      2;;.Z4J

D;F;;E"&&;D;F;@@dLAvvd# H HE<D<V<c;''xx4%
r   c                 h    [         R                  " U R                  S5      5      R                  5       $ )a  
Return the indices of unmasked elements that are not zero.

Returns a tuple of arrays, one for each dimension, containing the
indices of the non-zero elements in that dimension. The corresponding
non-zero values can be obtained with::

    a[a.nonzero()]

To group the indices by element, rather than dimension, use
instead::

    np.transpose(a.nonzero())

The result of this is always a 2d array, with a row for each non-zero
element.

Parameters
----------
None

Returns
-------
tuple_of_arrays : tuple
    Indices of elements that are non-zero.

See Also
--------
numpy.nonzero :
    Function operating on ndarrays.
flatnonzero :
    Return indices that are non-zero in the flattened version of the input
    array.
numpy.ndarray.nonzero :
    Equivalent ndarray method.
count_nonzero :
    Counts the number of non-zero elements in the input array.

Examples
--------
>>> import numpy as np
>>> import numpy.ma as ma
>>> x = ma.array(np.eye(3))
>>> x
masked_array(
  data=[[1., 0., 0.],
        [0., 1., 0.],
        [0., 0., 1.]],
  mask=False,
  fill_value=1e+20)
>>> x.nonzero()
(array([0, 1, 2]), array([0, 1, 2]))

Masked elements are ignored.

>>> x[1, 1] = ma.masked
>>> x
masked_array(
  data=[[1.0, 0.0, 0.0],
        [0.0, --, 0.0],
        [0.0, 0.0, 1.0]],
  mask=[[False, False, False],
        [False,  True, False],
        [False, False, False]],
  fill_value=1e+20)
>>> x.nonzero()
(array([0, 2]), array([0, 2]))

Indices can also be grouped by element.

>>> np.transpose(x.nonzero())
array([[0, 0],
       [2, 2]])

A common use for ``nonzero`` is to find the indices of an array, where
a condition is True.  Given an array `a`, the condition `a` > 3 is a
boolean array and since False is interpreted as 0, ma.nonzero(a > 3)
yields the indices of the `a` where the condition is true.

>>> a = ma.array([[1,2,3],[4,5,6],[7,8,9]])
>>> a > 3
masked_array(
  data=[[False, False, False],
        [ True,  True,  True],
        [ True,  True,  True]],
  mask=False,
  fill_value=True)
>>> ma.nonzero(a > 3)
(array([1, 1, 1, 2, 2, 2]), array([0, 1, 2, 0, 1, 2]))

The ``nonzero`` method of the condition array can also be called.

>>> (a > 3).nonzero()
(array([1, 1, 1, 2, 2, 2]), array([0, 1, 2, 0, 1, 2]))

r   )r  r0   rN   r   r  s    r   r   MaskedArray.nonzero  s%    B zz$++a.)1133r   c                    > U R                   nU[        L a   [        T	U ]  XUUS9nUR	                  U5      $ U R                  XUS9nUR	                  U5      R                  S5      R                  SUS9$ )z(
(this docstring should be overwritten)
)offsetaxis1axis2r  )r'  r(  r)  r   r   r:  )rn  r   r  r   r  rF   rN   r   )
r|  r'  r(  r)  r  r  r   rU  r   r  s
            r   r   MaskedArray.traceD  sy    
 JJ;W]&U'* # ,F==''VFA88E?))!,00bc0BBr   c                     [        XX#S9$ )a`  
a.dot(b, out=None)

Masked dot product of two arrays. Note that `out` and `strict` are
located in different positions than in `ma.dot`. In order to
maintain compatibility with the functional version, it is
recommended that the optional arguments be treated as keyword only.
At some point that may be mandatory.

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.

See Also
--------
numpy.ma.dot : equivalent function

)r  strict)dot)r|  r   r  r,  s       r   r-  MaskedArray.dotS  s    B 433r   c                 2   U[         R                  L a  0 OSU0nU R                  n[        Xa40 UD6nUct  U R	                  S5      R
                  " U4SU0UD6n[        USS5      n	U	(       a-  UR                  [        U 5      5      nUR                  U5        U$ U(       a  [        nU$ U R	                  S5      R
                  " U4X#S.UD6n[        U[        5      (       a5  [        U5      n
U
[        L a  [        UR                   5      =ol        Xzl        U$ )an  
Return the sum of the array elements over the given axis.

Masked elements are set to 0 internally.

Refer to `numpy.sum` for full documentation.

See Also
--------
numpy.ndarray.sum : corresponding function for ndarrays
numpy.sum : equivalent function

Examples
--------
>>> import numpy as np
>>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
>>> x
masked_array(
  data=[[1, --, 3],
        [--, 5, --],
        [7, --, 9]],
  mask=[[False,  True, False],
        [ True, False,  True],
        [False,  True, False]],
  fill_value=999999)
>>> x.sum()
25
>>> x.sum(axis=1)
masked_array(data=[4, 5, 16],
             mask=[False, False, False],
       fill_value=999999)
>>> x.sum(axis=0)
masked_array(data=[8, 5, 12],
             mask=[False, False, False],
       fill_value=999999)
>>> print(type(x.sum(axis=0, dtype=np.int64)[0]))
<class 'numpy.int64'>

r4  r   r  r   r  r  )r  r
   rn  r5  rN   r   r  ri  r/  r  rw   r  r   rY   r   ru   r   r  r|  r  r  r  r4  r  rn  r  rU  rndimoutmasks              r   r   MaskedArray.sumv  s    P  2;;.Z4J

"59&9;[[^''DEDVDFFFA.ET$Z0""7+ M MQ##DII&Ic;''clG& &4SYY&??)"L
r   c                    U R                  S5      R                  XUS9nUb2  [        U[        5      (       a  UR	                  U R
                  5        U$ UR                  [        U 5      5      nUR	                  U R                  5        U$ )aa  
Return the cumulative sum of the array elements over the given axis.

Masked values are set to 0 internally during the computation.
However, their position is saved, and the result will be masked at
the same locations.

Refer to `numpy.cumsum` for full documentation.

Notes
-----
The mask is lost if `out` is not a valid :class:`ma.MaskedArray` !

Arithmetic is modular when using integer types, and no error is
raised on overflow.

See Also
--------
numpy.ndarray.cumsum : corresponding function for ndarrays
numpy.cumsum : equivalent function

Examples
--------
>>> import numpy as np
>>> marr = np.ma.array(np.arange(10), mask=[0,0,0,1,1,1,0,0,0,0])
>>> marr.cumsum()
masked_array(data=[0, 1, 3, --, --, --, 9, 16, 24, 33],
             mask=[False, False, False,  True,  True,  True, False, False,
                   False, False],
       fill_value=999999)

r   r  r  r  )	rN   rC   r  r   r  rl  ri  r/  rn  r|  r  r  r  rU  s        r   rC   MaskedArray.cumsum  sr    B Q&&D3&G?#{++		*JT$Z(4::&r   c                 2   U[         R                  L a  0 OSU0nU R                  n[        Xa40 UD6nUct  U R	                  S5      R
                  " U4SU0UD6n[        USS5      n	U	(       a-  UR                  [        U 5      5      nUR                  U5        U$ U(       a  [        nU$ U R	                  S5      R
                  " U4X#S.UD6n[        U[        5      (       a5  [        U5      n
U
[        L a  [        UR                   5      =ol        Xzl        U$ )av  
Return the product of the array elements over the given axis.

Masked elements are set to 1 internally for computation.

Refer to `numpy.prod` for full documentation.

Notes
-----
Arithmetic is modular when using integer types, and no error is raised
on overflow.

See Also
--------
numpy.ndarray.prod : corresponding function for ndarrays
numpy.prod : equivalent function
r4  r   r  r   r   r0  )r  r
   rn  r5  rN   r   r  ri  r/  r  rw   r  r   rY   r   ru   r   r  r1  s              r   r   MaskedArray.prod  s    $  2;;.Z4J

"59&9;[[^((EUEfEFFFA.ET$Z0""7+ M MQ$$TJJ6Jc;''clG& &4SYY&??)"L
r   c                    U R                  S5      R                  XUS9nUb2  [        U[        5      (       a  UR	                  U R
                  5        U$ UR                  [        U 5      5      nUR	                  U R
                  5        U$ )a  
Return the cumulative product of the array elements over the given axis.

Masked values are set to 1 internally during the computation.
However, their position is saved, and the result will be masked at
the same locations.

Refer to `numpy.cumprod` for full documentation.

Notes
-----
The mask is lost if `out` is not a valid MaskedArray !

Arithmetic is modular when using integer types, and no error is
raised on overflow.

See Also
--------
numpy.ndarray.cumprod : corresponding function for ndarrays
numpy.cumprod : equivalent function
r   r6  )rN   rB   r  r   r  rn  ri  r/  r7  s        r   rB   MaskedArray.cumprod	  sq    , Q''TC'H?#{++

+JT$Z(4::&r   c                   > U[         R                  L a  0 OSU0nU R                  [        L a  [        TU ]  " SXS.UD6S   nGO SnUc  [        U R                  R                  [        R                  [        R                  45      (       a  [        R                  " S5      nOK[        U R                  R                  [        R                  5      (       a  [        R                  " S5      nSnU R                  " SXS.UD6nU R                  " SSU0UD6n	U	R                   S:X  a  U	S	:X  a  ["        nO1U(       a"  U R                  R                  US
-  U	-  5      nOUS
-  U	-  nUb\  Xcl        ['        U[(        5      (       a?  [+        U5      n
U
[        L a  [-        UR                   5      =ol        [+        U5      U
l        U$ U$ )a/  
Returns the average of the array elements along given axis.

Masked entries are ignored, and result elements which are not
finite will be masked.

Refer to `numpy.mean` for full documentation.

See Also
--------
numpy.ndarray.mean : corresponding function for ndarrays
numpy.mean : Equivalent function
numpy.ma.average : Weighted average.

Examples
--------
>>> import numpy as np
>>> 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

r4  r  r   Ff8f4Tr  r   r  )r  r
   rn  r   r  r   r^  r  r/  ntypesintegerr  mufloat16r   rA   r   rw   r  r  r   rY   ru   )r|  r  r  r  r4  r  rU  is_float16_resultdsumcntr3  r  s              r   r   MaskedArray.mean(  se   6  2;;.Z4J::W\CtCFCBGF %}djjoo/LMMHHTNE

@@HHTNE(,%88==f=D**1$1&1CyyBC1H"S9S?H#{++!#,f$*8*CCGi&vJr   c                 V    U R                  X5      nU(       d  X-
  $ U [        X15      -
  $ )a  
Compute the anomalies (deviations from the arithmetic mean)
along the given axis.

Returns an array of anomalies, with the same shape as the input and
where the arithmetic mean is computed along the given axis.

Parameters
----------
axis : int, optional
    Axis over which the anomalies are taken.
    The default is to use the mean of the flattened array as reference.
dtype : dtype, optional
    Type to use in computing the variance. For arrays of integer type
     the default is float32; for arrays of float types it is the same as
     the array type.

See Also
--------
mean : Compute the mean of the array.

Examples
--------
>>> import numpy as np
>>> a = np.ma.array([1,2,3])
>>> a.anom()
masked_array(data=[-1.,  0.,  1.],
             mask=False,
       fill_value=1e+20)

)r   r   )r|  r  r  r   s       r   r   MaskedArray.anom`  s-    @ IId"8O+a...r   c                   > 0 nU[         R                  La  XWS'   U R                  [        L a^  U[         R                  La  XgS'   [        TU ]  " SXX4S.UD6S   nUb,  [        U[        5      (       a  UR                  [        5        U$ U$ U R                  " SSU0UD6U-
  n	U[         R                  La  X-
  n
OX R                  XSS9-
  n
[        U 5      (       a  [        R                  " U
5      S-  n
OX-  n
[        U
R                  " U40 UD6U	5      R!                  [#        U 5      5      nUR$                  (       aA  ['        U R                  R(                  " U40 UD6U	S	:*  5      Ul        UR+                  U 5        O[-        U5      (       av  [.        nUbm  [        U[        5      (       a  S	Ul        UR                  S5        U$ UR2                  R4                  S
;   a  Sn[7        U5      e[         R8                  Ul        U$ Ub8  Xl        [        U[        5      (       a  UR                  UR:                  5        U$ U$ )a-  
Returns the variance of the array elements along given axis.

Masked entries are ignored, and result elements which are not
finite will be masked.

Refer to `numpy.var` for full documentation.

See Also
--------
numpy.ndarray.var : corresponding function for ndarrays
numpy.var : Equivalent function
r4  r   )r  r  r  ddofr   r  Tr4  r  r   biu>Masked data information would be lost in one or more location.)r  r
   rn  r   r  r   r  r   r  rA   r   r   r  r   rH   r   ri  r/  r   rv   r   r  rY   rw   r  r  r%  r   r  rl  )r|  r  r  r  rK  r4  r   r  rX  rF  danomdvarr  r  s                r   r   MaskedArray.var  s    2;;&!): ::2;;&!%v'+ (4# ( &((*,Cc;//OOF+
J jj-d-f-4r{{"KE99T49@@ENN5)Q.ENEeii//5::4:F99 !?!?#(LDJd#T]]Dc;// CHOOD) 
 YY^^u,.F#F++!vvCH
?H#{++		*Jr   c                     U[         R                  L a  0 OSU0nU R                  " XX440 UD6nU[        La'  Ub  [         R                  " USUSS9  U$ [        U5      nU$ )z
Returns the standard deviation of the array elements along given axis.

Masked entries are ignored.

Refer to `numpy.std` for full documentation.

See Also
--------
numpy.ndarray.std : corresponding function for ndarrays
numpy.std : Equivalent function
r4  g      ?r  r  r  )r  r
   r   rw   r   r   )	r|  r  r  r  rK  r4  r   r  rP  s	            r   r   MaskedArray.std  sb      2;;.Z4JxxS9&9vcsH=
:Dr   c                 f   U R                   R                  XS9R                  [        U 5      5      nUR                  S:  a#  U R
                  Ul        UR                  U 5        OU R
                  (       a  [        nUc  U$ [        U[        5      (       a  UR                  U R
                  5        U$ )a  
Return each element rounded to the given number of decimals.

Refer to `numpy.around` for full documentation.

See Also
--------
numpy.ndarray.round : corresponding function for ndarrays
numpy.around : equivalent function

Examples
--------
>>> import numpy as np
>>> import numpy.ma as ma
>>> x = ma.array([1.35, 2.5, 1.5, 1.75, 2.25, 2.75],
...              mask=[0, 0, 0, 1, 0, 0])
>>> ma.round(x)
masked_array(data=[1.0, 2.0, 2.0, --, 2.0, 3.0],
             mask=[False, False, False,  True, False, False],
        fill_value=1e+20)

)decimalsr  r   )rg  r   ri  r/  r   rn  r  rw   r  r   r  )r|  rV  r  rU  s       r   r   MaskedArray.round  s    . !!8!=BB4:N;;?::FL%ZZF;Mc;''OODJJ'
r   stablec                p   U(       a  [        S5      eU[        R                  L a  [        U 5      nUcc  U(       aQ  [        R                  " U R
                  [        R                  5      (       a  [        R                  nO[        U 5      nO[        U 5      nU R                  U5      nUR                  XUS9$ )a  
Return an ndarray of indices that sort the array along the
specified axis.  Masked values are filled beforehand to
`fill_value`.

Parameters
----------
axis : int, optional
    Axis along which to sort. If None, the default, the flattened array
    is used.
kind : {'quicksort', 'mergesort', 'heapsort', 'stable'}, optional
    The sorting algorithm used.
order : list, optional
    When `a` is an array with fields defined, this argument specifies
    which fields to compare first, second, etc.  Not all fields need be
    specified.
endwith : {True, False}, optional
    Whether missing values (if any) should be treated as the largest values
    (True) or the smallest values (False)
    When the array contains unmasked values at the same extremes of the
    datatype, the ordering of these values and the masked values is
    undefined.
fill_value : scalar or None, optional
    Value used internally for the masked values.
    If ``fill_value`` is not None, it supersedes ``endwith``.
stable : bool, optional
    Only for compatibility with ``np.argsort``. Ignored.

Returns
-------
index_array : ndarray, int
    Array of indices that sort `a` along the specified axis.
    In other words, ``a[index_array]`` yields a sorted `a`.

See Also
--------
ma.MaskedArray.sort : Describes sorting algorithms used.
lexsort : Indirect stable sort with multiple keys.
numpy.ndarray.sort : Inplace sort.

Notes
-----
See `sort` for notes on the different sorting algorithms.

Examples
--------
>>> import numpy as np
>>> a = np.ma.array([3,2,1], mask=[False, False, True])
>>> a
masked_array(data=[3, 2, --],
             mask=[False, False,  True],
       fill_value=999999)
>>> a.argsort()
array([1, 0, 2])

6`stable` parameter is not supported for masked arrays.r  r%  r  )rI  r  r
   r   rS  r  rT  r  r   r   rN   r-   )r|  r  r%  r  endwithrM  rY  rN   s           r   r-   MaskedArray.argsort  s    t H 
 2;;*40D==R[[99!#J!3D!9J/5
Z(~~4%~@@r   rL  c                    Uc  [        U 5      nU R                  U5      R                  [        5      nU[        R
                  L a  SO
[        U5      nUR                  XUS9$ )aC  
Return array of indices to the minimum values along the given axis.

Parameters
----------
axis : {None, integer}
    If None, the index is into the flattened array, otherwise along
    the specified axis
fill_value : scalar or None, optional
    Value used to fill in the masked values.  If None, the output of
    minimum_fill_value(self._data) is used instead.
out : {None, array}, optional
    Array into which the result can be placed. Its type is preserved
    and it must be of the right shape to hold the output.

Returns
-------
ndarray or scalar
    If multi-dimension input, returns a new ndarray of indices to the
    minimum values along the given axis.  Otherwise, returns a scalar
    of index to the minimum values along the given axis.

Examples
--------
>>> import numpy as np
>>> x = np.ma.array(np.arange(4), mask=[1,1,0,0])
>>> x.shape = (2,2)
>>> x
masked_array(
  data=[[--, --],
        [2, 3]],
  mask=[[ True,  True],
        [False, False]],
  fill_value=999999)
>>> x.argmin(axis=0, fill_value=-1)
array([0, 0])
>>> x.argmin(axis=0, fill_value=9)
array([1, 1])

Fr  r4  )r   rN   ri  r   r  r
   r  r,   r|  r  rM  r  r4  r  s         r   r,   MaskedArray.argmin_  sW    T +D1JKK
#((1$35hxxx99r   c                    Uc  [        U R                  5      nU R                  U5      R                  [        5      nU[
        R                  L a  SO
[        U5      nUR                  XUS9$ )a  
Returns array of indices of the maximum values along the given axis.
Masked values are treated as if they had the value fill_value.

Parameters
----------
axis : {None, integer}
    If None, the index is into the flattened array, otherwise along
    the specified axis
fill_value : scalar or None, optional
    Value used to fill in the masked values.  If None, the output of
    maximum_fill_value(self._data) is used instead.
out : {None, array}, optional
    Array into which the result can be placed. Its type is preserved
    and it must be of the right shape to hold the output.

Returns
-------
index_array : {integer_array}

Examples
--------
>>> import numpy as np
>>> a = np.arange(6).reshape(2,3)
>>> a.argmax()
5
>>> a.argmax(0)
array([1, 1, 1])
>>> a.argmax(1)
array([2, 2])

Fr`  )	r   rg  rN   ri  r   r  r
   r  r+   ra  s         r   r+   MaskedArray.argmax  s[    D +DJJ7JKK
#((1$35hxxx99r   c                    U(       a  [        S5      eU R                  [        L a  [        R                  " XX#S9  gU [
        L a  gU R                  XUXTS9n[        R                  " XUS9U S'   g)a  
Sort the array, in-place

Parameters
----------
a : array_like
    Array to be sorted.
axis : int, optional
    Axis along which to sort. If None, the array is flattened before
    sorting. The default is -1, which sorts along the last axis.
kind : {'quicksort', 'mergesort', 'heapsort', 'stable'}, optional
    The sorting algorithm used.
order : list, optional
    When `a` is a structured array, this argument specifies which fields
    to compare first, second, and so on.  This list does not need to
    include all of the fields.
endwith : {True, False}, optional
    Whether missing values (if any) should be treated as the largest values
    (True) or the smallest values (False)
    When the array contains unmasked values sorting at the same extremes of the
    datatype, the ordering of these values and the masked values is
    undefined.
fill_value : scalar or None, optional
    Value used internally for the masked values.
    If ``fill_value`` is not None, it supersedes ``endwith``.
stable : bool, optional
    Only for compatibility with ``np.sort``. Ignored.

Returns
-------
sorted_array : ndarray
    Array of the same type and shape as `a`.

See Also
--------
numpy.ndarray.sort : Method to sort an array in-place.
argsort : Indirect sort.
lexsort : Indirect stable sort on multiple keys.
searchsorted : Find elements in a sorted array.

Notes
-----
See ``sort`` for notes on the different sorting algorithms.

Examples
--------
>>> import numpy as np
>>> a = np.ma.array([1, 2, 5, 4, 3],mask=[0, 1, 0, 1, 0])
>>> # Default
>>> a.sort()
>>> a
masked_array(data=[1, 3, 5, --, --],
             mask=[False, False, False,  True,  True],
       fill_value=999999)

>>> a = np.ma.array([1, 2, 5, 4, 3],mask=[0, 1, 0, 1, 0])
>>> # Put missing values in the front
>>> a.sort(endwith=False)
>>> a
masked_array(data=[--, --, 1, 3, 5],
             mask=[ True,  True, False, False, False],
       fill_value=999999)

>>> a = np.ma.array([1, 2, 5, 4, 3],mask=[0, 1, 0, 1, 0])
>>> # fill_value takes over endwith
>>> a.sort(endwith=False, fill_value=3)
>>> a
masked_array(data=[1, --, --, 3, 5],
             mask=[False,  True,  True, False, False],
       fill_value=999999)

r[  r\  N)r  r%  r  rM  r]  r  .)	rI  rn  r   r   r   rw   r-   r  take_along_axis)r|  r  r%  r  r]  rM  rY  sidxs           r   r   MaskedArray.sort  st    T H  ::LLtA6>||'1  D &&t=S	r   c                 :   U[         R                  L a  0 OSU0nU R                  n[        Xa40 UD6nUc  [	        U 5      nUc  U R                  U5      R                  " SXS.UD6R                  [        U 5      5      nUR                  (       aC  UR                  U5        UR                  (       a  [         R                  " XR                  US9  U$ U(       a  [        nU$ U R                  U5      R                  " SXS.UD6  [        U[        5      (       a7  [!        U5      n	U	["        L a  [%        UR&                  5      =ol        Xyl        U$ UR*                  R,                  S;   a  Sn
[/        U
5      e[         R                  " U[         R0                  US9  U$ )a  
Return the minimum along a given axis.

Parameters
----------
axis : None or int or tuple of ints, optional
    Axis along which to operate.  By default, ``axis`` is None and the
    flattened input is used.
    If this is a tuple of ints, the minimum is selected over multiple
    axes, instead of a single axis or all the axes as before.
out : array_like, optional
    Alternative output array in which to place the result.  Must be of
    the same shape and buffer length as the expected output.
fill_value : scalar or None, optional
    Value used to fill in the masked values.
    If None, use the output of `minimum_fill_value`.
keepdims : bool, optional
    If this is set to True, the axes which are reduced are left
    in the result as dimensions with size one. With this option,
    the result will broadcast correctly against the array.

Returns
-------
amin : array_like
    New array holding the result.
    If ``out`` was specified, ``out`` is returned.

See Also
--------
ma.minimum_fill_value
    Returns the minimum filling value for a given datatype.

Examples
--------
>>> import numpy.ma as ma
>>> x = [[1., -2., 3.], [0.2, -0.7, 0.1]]
>>> mask = [[1, 1, 0], [0, 0, 1]]
>>> masked_x = ma.masked_array(x, mask)
>>> masked_x
masked_array(
  data=[[--, --, 3.0],
        [0.2, -0.7, --]],
  mask=[[ True,  True, False],
        [False, False,  True]],
  fill_value=1e+20)
>>> ma.min(masked_x)
-0.7
>>> ma.min(masked_x, axis=-1)
masked_array(data=[3.0, -0.7],
             mask=[False, False],
        fill_value=1e+20)
>>> ma.min(masked_x, axis=0, keepdims=True)
masked_array(data=[[0.2, -0.7, 3.0]],
             mask=[[False, False, False]],
        fill_value=1e+20)
>>> mask = [[1, 1, 1,], [1, 1, 1]]
>>> masked_x = ma.masked_array(x, mask)
>>> ma.min(masked_x, axis=0)
masked_array(data=[--, --, --],
             mask=[ True,  True,  True],
        fill_value=1e+20,
            dtype=float64)
r4  r:  r  rM  rN  r   )r  r
   rn  r5  r   rN   r   ri  r/  r   r  r  rM  rw   r  r   rY   r   ru   r   r  r  r%  r   r  r|  r  r  rM  r4  r  rn  r  rU  r3  r  s              r   r   MaskedArray.min  sb   @  2;;.Z4J

"59&9+D1J;[[,00 ..&,..2d4:.> {{""7+<<IIf&7&7wG M MJ##AA&Ac;''clG& &4SYY&??)"L 
 yy~~&&''IIc2661
r   c                 :   U[         R                  L a  0 OSU0nU R                  n[        Xa40 UD6nUc  [	        U 5      nUc  U R                  U5      R                  " SXS.UD6R                  [        U 5      5      nUR                  (       aC  UR                  U5        UR                  (       a  [         R                  " XR                  US9  U$ U(       a  [        nU$ U R                  U5      R                  " SXS.UD6  [        U[        5      (       a7  [!        U5      n	U	["        L a  [%        UR&                  5      =ol        Xyl        U$ UR*                  R,                  S;   a  Sn
[/        U
5      e[         R                  " U[         R0                  US9  U$ )a  
Return the maximum along a given axis.

Parameters
----------
axis : None or int or tuple of ints, optional
    Axis along which to operate.  By default, ``axis`` is None and the
    flattened input is used.
    If this is a tuple of ints, the maximum is selected over multiple
    axes, instead of a single axis or all the axes as before.
out : array_like, optional
    Alternative output array in which to place the result.  Must
    be of the same shape and buffer length as the expected output.
fill_value : scalar or None, optional
    Value used to fill in the masked values.
    If None, use the output of maximum_fill_value().
keepdims : bool, optional
    If this is set to True, the axes which are reduced are left
    in the result as dimensions with size one. With this option,
    the result will broadcast correctly against the array.

Returns
-------
amax : array_like
    New array holding the result.
    If ``out`` was specified, ``out`` is returned.

See Also
--------
ma.maximum_fill_value
    Returns the maximum filling value for a given datatype.

Examples
--------
>>> import numpy.ma as ma
>>> x = [[-1., 2.5], [4., -2.], [3., 0.]]
>>> mask = [[0, 0], [1, 0], [1, 0]]
>>> masked_x = ma.masked_array(x, mask)
>>> masked_x
masked_array(
  data=[[-1.0, 2.5],
        [--, -2.0],
        [--, 0.0]],
  mask=[[False, False],
        [ True, False],
        [ True, False]],
  fill_value=1e+20)
>>> ma.max(masked_x)
2.5
>>> ma.max(masked_x, axis=0)
masked_array(data=[-1.0, 2.5],
             mask=[False, False],
       fill_value=1e+20)
>>> ma.max(masked_x, axis=1, keepdims=True)
masked_array(
  data=[[2.5],
        [-2.0],
        [0.0]],
  mask=[[False],
        [False],
        [False]],
  fill_value=1e+20)
>>> mask = [[1, 1], [1, 1], [1, 1]]
>>> masked_x = ma.masked_array(x, mask)
>>> ma.max(masked_x, axis=1)
masked_array(data=[--, --, --],
             mask=[ True,  True,  True],
       fill_value=1e+20,
            dtype=float64)
r4  r:  r  rM  rN  r   )r  r
   rn  r5  r   rN   r   ri  r/  r   r  r  rM  rw   r  r   rY   r   ru   r   r  r  r%  r   r  rj  s              r   r   MaskedArray.maxt  sb   N  2;;.Z4J

"59&9+D1J;[[,00 ..&,..2d4:.> {{""7+<<IIf&7&7wG M MJ##AA&Ac;''clG& &4SYY&??)"L 
 yy~~&&''IIc2661
r   c                     Uc$  U R                  XUS9nXPR                  XUS9-  nU$ U R                  XUUS9Ul        U R                  XUS9n[        R                  " X&USS9  U$ )a  
Return (maximum - minimum) along the given dimension
(i.e. peak-to-peak value).

.. warning::
    `ptp` preserves the data type of the array. This means the
    return value for an input of signed integers with n bits
    (e.g. `np.int8`, `np.int16`, etc) is also a signed integer
    with n bits.  In that case, peak-to-peak values greater than
    ``2**(n-1)-1`` will be returned as negative values. An example
    with a work-around is shown below.

Parameters
----------
axis : {None, int}, optional
    Axis along which to find the peaks.  If None (default) the
    flattened array is used.
out : {None, array_like}, optional
    Alternative output array in which to place the result. It must
    have the same shape and buffer length as the expected output
    but the type will be cast if necessary.
fill_value : scalar or None, optional
    Value used to fill in the masked values.
keepdims : bool, optional
    If this is set to True, the axes which are reduced are left
    in the result as dimensions with size one. With this option,
    the result will broadcast correctly against the array.

Returns
-------
ptp : ndarray.
    A new array holding the result, unless ``out`` was
    specified, in which case a reference to ``out`` is returned.

Examples
--------
>>> import numpy as np
>>> x = np.ma.MaskedArray([[4, 9, 2, 10],
...                        [6, 9, 7, 12]])

>>> x.ptp(axis=1)
masked_array(data=[8, 6],
             mask=False,
       fill_value=999999)

>>> x.ptp(axis=0)
masked_array(data=[2, 0, 5, 2],
             mask=False,
       fill_value=999999)

>>> x.ptp()
10

This example shows that a negative value can be returned when
the input is an array of signed integers.

>>> y = np.ma.MaskedArray([[1, 127],
...                        [0, 127],
...                        [-1, 127],
...                        [-2, 127]], dtype=np.int8)
>>> y.ptp(axis=1)
masked_array(data=[ 126,  127, -128, -127],
             mask=False,
       fill_value=np.int64(999999),
            dtype=int8)

A work-around is to use the `view()` method to view the result as
unsigned integers with the same bit width:

>>> y.ptp(axis=1).view(np.uint8)
masked_array(data=[126, 127, 128, 129],
             mask=False,
       fill_value=np.uint64(999999),
            dtype=uint8)
)r  rM  r4  )r  r  rM  r4  r  rS  )r   r   r  r  r   )r|  r  r  rM  r4  rU  	min_values          r   r   MaskedArray.ptp  s    X ;XX4'/  1FhhD(0  2 2FM88:%-  /HH$&.  0	
CX>
r   c                 ~   > [         R                  " SU R                  R                   S3SS9  [        TU ]  " U0 UD6$ )Nz3Warning: 'partition' will ignore the 'mask' of the r.  r  r   )r   r   r  r   r  	partitionr|  r  r  r  s      r   rr  MaskedArray.partition7  sE       $ 7 78;!"	$ w $1&11r   c                 ~   > [         R                  " SU R                  R                   S3SS9  [        TU ]  " U0 UD6$ )Nz6Warning: 'argpartition' will ignore the 'mask' of the r.  r  r   )r   r   r  r   r  argpartitionrs  s      r   rv  MaskedArray.argpartition=  sE       $ 7 78;!"	$ w#T4V44r   c                    U R                   U R                  pe[        U 5      n[        U5      nU[        La  UR                  S5      nUc#  UR                  XUS9S   R                  U5      nO[        R                  " XQX$US9  [        U[        5      (       a1  U[        L a  Un	OUR                  XUS9n	X-  n	UR                  U	5        US   $ )aD  
Take elements from a masked array along an axis.

This function does the same thing as "fancy" indexing (indexing arrays
using arrays) for masked arrays. It can be easier to use if you need
elements along a given axis.

Parameters
----------
a : masked_array
    The source masked array.
indices : array_like
    The indices of the values to extract. Also allow scalars for indices.
axis : int, optional
    The axis over which to select values. By default, the flattened
    input array is used.
out : MaskedArray, optional
    If provided, the result will be placed in this array. It should
    be of the appropriate shape and dtype. Note that `out` is always
    buffered if `mode='raise'`; use other modes for better performance.
mode : {'raise', 'wrap', 'clip'}, optional
    Specifies how out-of-bounds indices will behave.

    * 'raise' -- raise an error (default)
    * 'wrap' -- wrap around
    * 'clip' -- clip to the range

    'clip' mode means that all indices that are too large are replaced
    by the index that addresses the last element along that axis. Note
    that this disables indexing with negative numbers.

Returns
-------
out : MaskedArray
    The returned array has the same type as `a`.

See Also
--------
numpy.take : Equivalent function for ndarrays.
compress : Take elements using a boolean mask.
take_along_axis : Take elements by matching the array and the index arrays.

Notes
-----
This function behaves similarly to `numpy.take`, but it handles masked
values. The mask is retained in the output array, and masked values
in the input array remain masked in the output.

Examples
--------
>>> import numpy as np
>>> a = np.ma.array([4, 3, 5, 7, 6, 8], mask=[0, 0, 1, 0, 1, 0])
>>> indices = [0, 1, 4]
>>> np.ma.take(a, indices)
masked_array(data=[4, 3, --],
            mask=[False, False,  True],
    fill_value=999999)

When `indices` is not one-dimensional, the output also has these dimensions:

>>> np.ma.take(a, [[0, 1], [2, 3]])
masked_array(data=[[4, 3],
                [--, 7]],
            mask=[[False, False],
                [ True, False]],
    fill_value=999999)
r   )r  r  .)r  r  r  r   )rg  rn  r/  rY   r   rN   r   ri  r  r  r   r  )
r|  ra   r  r  r  rg  rn  rb  maskindicesr3  s
             r   r   MaskedArray.takeC  s    H **djj4jg&f$nnQ'G ;**Wd*;C@EEcJCGGEcBc;''%**Wd*C&OOG$2wr   r=   rF   flattenr   r   r   c                 "    U R                  5       $ r  )r   r  s    r   <lambda>MaskedArray.<lambda>  s    4>>#3r   r   c                     U R                   S:  a  [        S5      eU R                  [        L a  [	        U R
                  R                  S9$ [	        U R                  R                  U R                  R                  S9$ )a  
Return the matrix-transpose of the masked array.

The matrix transpose is the transpose of the last two dimensions, even
if the array is of higher dimension.

.. versionadded:: 2.0

Returns
-------
result: MaskedArray
    The masked array with the last two dimensions transposed

Raises
------
ValueError
    If the array is of dimension less than 2.

See Also
--------
ndarray.mT:
    Equivalent method for arrays
r  z+matrix transpose with ndim < 2 is undefined)rj  )rj  rl  )	r   rI  rn  r   rx   rg  mTrj  rl  r  s    r   r  MaskedArray.mT  sW    4 99q=JKK::TZZ]]33TYY\\		EEr   c                 p   U R                   nU[        L a  U R                  R                  5       $ Ub  U R	                  U5      R                  5       $ U R
                  R                  nU(       aS  U R                  R                  U Vs/ s H
  oD[        4PM     sn5      nU H  nSXV   X&   '   M     UR                  5       $ U[        L a  S/$ U R                  n[        R                  " U R                  R                  5       [        S9nSXRR                  5       '   Xul	        UR                  5       $ s  snf )a  
Return the data portion of the masked array as a hierarchical Python list.

Data items are converted to the nearest compatible Python type.
Masked values are converted to `fill_value`. If `fill_value` is None,
the corresponding entries in the output list will be ``None``.

Parameters
----------
fill_value : scalar, optional
    The value to use for invalid entries. Default is None.

Returns
-------
result : list
    The Python list representation of the masked array.

Examples
--------
>>> import numpy as np
>>> 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]]

Nr  )rn  r   rg  tolistrN   r  r  r  rJ  r   r  r   r   )r|  rM  rn  r  r  rU  r  r  s           r   r  MaskedArray.tolist  s    8 

F?::$$&&!;;z*1133

  ZZ&&U'CUFU'CDF&*	%(# ==?"F?6M::$****,F; ${{}}} (Ds   D3c                 T    [         R                  " S[        SS9  U R                  XS9$ )z
A compatibility alias for `tobytes`, with exactly the same behavior.

Despite its name, it returns `bytes` not `str`\ s.

.. deprecated:: 1.19.0
z0tostring() is deprecated. Use tobytes() instead.r  r   r  )r   r   r3  tobytesr|  rM  r  s      r   tostringMaskedArray.tostring  s+     	>1	. ||J|44r   c                 >    U R                  U5      R                  US9$ )a  
Return the array data as a string containing the raw bytes in the array.

The array is filled with a fill value before the string conversion.

Parameters
----------
fill_value : scalar, optional
    Value used to fill in the masked values. Default is None, in which
    case `MaskedArray.fill_value` is used.
order : {'C','F','A'}, optional
    Order of the data item in the copy. Default is 'C'.

    - 'C'   -- C order (row major).
    - 'F'   -- Fortran order (column major).
    - 'A'   -- Any, current order of array.
    - None  -- Same as 'A'.

See Also
--------
numpy.ndarray.tobytes
tolist, tofile

Notes
-----
As for `ndarray.tobytes`, information about the shape, dtype, etc.,
but also about `fill_value`, will be lost.

Examples
--------
>>> import numpy as np
>>> x = np.ma.array(np.array([[1, 2], [3, 4]]), mask=[[0, 1], [1, 0]])
>>> x.tobytes()
b'\x01\x00\x00\x00\x00\x00\x00\x00?B\x0f\x00\x00\x00\x00\x00?B\x0f\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00'

r  )rN   r  r  s      r   r  MaskedArray.tobytes  s"    J {{:&..U.;;r   c                     [        S5      e)z
Save a masked array to a file in binary format.

.. warning::
  This function is not implemented yet.

Raises
------
NotImplementedError
    When `tofile` is called.

z)MaskedArray.tofile() not implemented yet.r  )r|  fidseprZ  s       r   tofileMaskedArray.tofile5  s     ""MNNr   c                    U R                   nU R                  nUc  [        U R                  U5      nU R                  R                   n[        R
                  " U R                  SU4SU4/S9nU R                  US'   U R                  US'   U$ )a  
Transforms a masked array into a flexible-type array.

The flexible type array that is returned will have two fields:

* the ``_data`` field stores the ``_data`` part of the array.
* the ``_mask`` field stores the ``_mask`` part of the array.

Parameters
----------
None

Returns
-------
record : ndarray
    A new flexible-type `ndarray` with two fields: the first element
    containing a value, the second element containing the corresponding
    mask boolean. The returned record shape matches self.shape.

Notes
-----
A side-effect of transforming a masked array into a flexible `ndarray` is
that meta information (``fill_value``, ...) will be lost.

Examples
--------
>>> import numpy as np
>>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
>>> x
masked_array(
  data=[[1, --, 3],
        [--, 5, --],
        [7, --, 9]],
  mask=[[False,  True, False],
        [ True, False,  True],
        [False,  True, False]],
  fill_value=999999)
>>> x.toflex()
array([[(1, False), (2,  True), (3, False)],
       [(4,  True), (5, False), (6,  True)],
       [(7, False), (8,  True), (9, False)]],
      dtype=[('_data', '<i8'), ('_mask', '?')])

rg  rn  )r   r  )r  rn  ru   r   r  r   rg  )r|  ddtypern  r  records        r   toflexMaskedArray.toflexD  s    \ 

="4::v6E!!$**$+V#4w6G"HJ**w**wr   c                    > SU R                   R                     n[        TU ]  5       S   nU[	        U 5      R                  U5      U R                  4-   $ )zGReturn the internal state of the masked array, for pickling
purposes.

CFr  )r  r	  r  
__reduce__rZ   r  r  )r|  cf
data_stater  s      r   __getstate__MaskedArray.__getstate__  sO    
 $**..!W')!,
\$/77;T=M=MNNNr   c                    > Uu  p#pEpgn[         T	U ]  X4XV45        U R                  R                  U[        U5      XW45        Xl        g)a+  Restore 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)r  __setstate__rn  rt   rM  )
r|  stater  shptypisfrawmskflvr  s
            r   r  MaskedArray.__setstate__  sH     -2)3Sc12

oc&:C EFr   c                 `    [         U R                  U R                  SS4U R                  5       4$ )z6Return a 3-tuple for pickling a MaskedArray.

        r  r   )_mareconstructr  r  r  r  s    r   r  MaskedArray.__reduce__  s1     $=!!#% 	%r   c                 V   SSK Jn  [        R                  [	        U 5      U SS9nUc  0 nX1[        U 5      '   U R                  R                  5        H  u  pEU" XQ5      UR                  U'   M     U R                  R                  (       a  U" UR                  5      UR                  S'   U$ )Nr   )deepcopyTr  .)r=   r  r   r  r/  r  r  r  r  	hasobjectrg  )r|  memor  copiedr[  vs         r   __deepcopy__MaskedArray.__deepcopy__  s    !$$T$ZD$A<DRXmm))+FQ!)!!2FOOA , :: ( 6FLLr   )r  r  rn  r  rM  NF)NNNFr  r	  r  )TFraise)r   r   r   NNr  r   NNTN)NNNFNNr  )Nr  )r   z%s)r   r   r   r   r   rr  r   _defaultmask_defaulthardmaskr   r  r>  r?  r  r  r  r  ri  r  r  r  r  propertyr  setterr   r  	_set_maskrl  r  r]   r   r  r  r!  rV  r&  r)  rg  rj  r  rM  r+  rV  fsetr   rN   r9   r8   rD  r  rs  rv  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  get_imagr  get_realr
   rA   r   r   r   r   r`   r  r   r!   r   r   r-  r   rC   r   r   rB   r   r   r   r   r   r-   r,   r+   r   r   r   r   rr  rv  r   r  r=   rF   r{  r   r   r   Tr   r  r  r  r  r  r  	torecordsr  r  r  r  r   r  r  s   @r   r   r   
  s   cJ LJ LOV4e!t4Nb4[Cz:xXt|B [[h1C 2CL   \\	 	   \\* *DL I! ! 
[[    @ @$ P P$$ * *X$    @  3" )$E#D$ $ 
[[  '  ' R % %&  __N__NOb"HGR>0a%F'HT444444  %%%%#(())""$""&&&*"
   2 yyH 2 yyH ^<@<~AF!$Tl:6(8  'R  <a4FC MM))EM!4F 4TBKK =~(T DdR[[ 'P G> DdR[[ 6p$/L 4T[[r{{IT &&..CK4T[[r{{0#J ;;TtNA+0NA`.:.:`&:&:P <@Y>(-Y>v $ `D $ hTWr25Yx DJ'H9%G(#F9%GJ'H34A[)IF FD2h5%<NO:v IO"% r   r   c                     [         R                  " XU5      n[         R                  " [         U[        U5      5      nU R                  XXSS9$ )zZInternal function that builds a new MaskedArray from the
information stored in a pickle.

)rl  r  )r   r  rt   )r  r&  	baseshapebasetyperg  rn  s         r   r  r    s>    
 OOI(;EOOGY0IJE??7?GGr   c                      ^  \ rS rSrSr\SSSSS4S jr\U 4S j5       rS r	S	 r
U 4S
 jr\rS rS rSS jrS rSrU =r$ )r   i  zF
Fake a 'void' object to use for masked array with structured dtypes.
NFTc                    U(       d  S OSn[         R                  " XXsS9nUR                  U 5      nXXl        U[        LaB  [        U[         R                  5      (       a  X(l        O [         R                  " U5      Ul        Ub  XHl
        U$ ! [         a*    [        U5      n	[         R                  " X)S9S   Ul         N>f = f)NT)r=   rf  r  r  r   )r  r   ri  r  r   r  rH  rn  r   rt   rM  )
r|  rj  rl  r  rM  r  r=   rf  rg  r  s
             r   r  mvoid.__new__  s    tTC

4 "v$(("C"$''$-EK
 !) ! C,U3F"$((4">r"BEKCs   (B 1CCc                    > [         TU ]  S   $ )Nr   )r  rg  r  s    r   rg  mvoid._data  s     w}R  r   c                     U R                   n[        X!   [        5      (       a2  [        U R                  U   X!   U R
                  U   U R                  S9$ U[        La  X!   (       a  [        $ U R                  U   $ )z
Get the index.

)rj  rl  rM  r  )	rn  r  r   rx   rg  r  r  r   rw   )r|  r  r   s      r   r  mvoid.__getitem__  sq    
 JJagw''  ZZ%AG++D1..* * F?qwMzz$r   c                     X R                   U'   U R                  (       a#  U R                  U==   [        USS5      -  ss'   g [        USS5      U R                  U'   g )Nrn  F)rg  r  rn  r  )r|  r  r@  s      r   r  mvoid.__setitem__  sI     

4>>JJtw >>&ugu=DJJtr   c                   > U R                   nU[        L a  [        U R                  5      $ [	        U R                  R
                  S5      n[        TU ]  nUR                  U5      n[        X@R                   [        5        [        U5      $ )Nr   )
rn  r   r(  rg  r  r  r  r  ru  r   )r|  r   rC  data_arrrZ  r  s        r   r  mvoid.__str__  sf    JJ;tzz?"&tzz'7'7=7=oof%sJJ0CD3xr   c              #      #    U R                   U R                  p!U[        L a  U Sh  vN   g[        X5       H  u  p4U(       a
  [        v   M  Uv   M     g N/7f)zDefines an iterator for mvoidN)rg  rn  r   r=  rw   )r|  rg  rn  r  r   s        r   r-  mvoid.__iter__  sG     **djjF?e+ LG	 , s   &AA0Ac                 6    U R                   R                  5       $ r  )rg  __len__r  s    r   r  mvoid.__len__  s    zz!!##r   c                 <    [        U 5      R                  U5      S   $ )a  
Return a copy with masked fields filled with a given value.

Parameters
----------
fill_value : array_like, optional
    The value to use for invalid entries. Can be scalar or
    non-scalar. If latter is the case, the filled array should
    be broadcastable over input array. Default is None, in
    which case the `fill_value` attribute is used instead.

Returns
-------
filled_void
    A `np.void` object

See Also
--------
MaskedArray.filled

r   )r0   rN   )r|  rM  s     r   rN   mvoid.filled  s    , t}##J/33r   c                 >   U R                   nU[        L a  U R                  R                  5       $ / n[	        U R                  U R                   5       H>  u  p4U(       a  UR                  S5        M  UR                  UR                  5       5        M@     [        U5      $ )z
Transforms the mvoid object into a tuple.

Masked fields are replaced by None.

Returns
-------
returned_tuple
    Tuple of fields
    N)rn  r   rg  r  r=  r"   r?  r  )r|  rn  rU  r  r   s        r   r  mvoid.tolist/  sv     

F?::$$&&$**djj1FQd# affh' 2 V}r   r   r  )r   r   r   r   r   r   r  r  rg  r  r  r  rs  r-  r  rN   r  r   r  r  s   @r   r   r     s`     "(tU$* ! ! ,>	 H
$40 r   r   c                 "    [        U [        5      $ )aq  
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 as np
>>> import numpy.ma as ma
>>> a = np.eye(3, 3)
>>> a
array([[ 1.,  0.,  0.],
       [ 0.,  1.,  0.],
       [ 0.,  0.,  1.]])
>>> m = ma.masked_values(a, 0)
>>> m
masked_array(
  data=[[1.0, --, --],
        [--, 1.0, --],
        [--, --, 1.0]],
  mask=[[False,  True,  True],
        [ True, False,  True],
        [ True,  True, False]],
  fill_value=0.0)
>>> ma.isMaskedArray(a)
False
>>> ma.isMaskedArray(m)
True
>>> ma.isMaskedArray([0, 1, 2])
False

)r  r   r  s    r   re   re   L  s    b a%%r   c                      ^  \ rS rSrSr\S 5       rS rU 4S jrSS jr	S r
S rS	 rS
 rS r\=r=r=r=r=rrCS rS rS rU 4S jrSrU =r$ )r]  i  Nc                 Z    U R                   S L=(       a    [        U R                   5      U L $ r  )_MaskedConstant__singletonr/  )rb  s    r   __has_singletonMaskedConstant.__has_singleton  s&     d*KtCOO/D/KKr   c                    U R                  5       (       dk  [        R                  " S5      n[        R                  " S5      nSUR                  l        SUR                  l        [        XS9R                  U 5      U l        U R                  $ )Nr  TFr  )_MaskedConstant__has_singletonr  r   r  	writeabler   ri  r  )rb  rj  rl  s      r   r  MaskedConstant.__new__  sj    ""$$ 88B<D88D>D $)DJJ #(DJJ 
 *$:??DCOr   c                    > U R                  5       (       d  [        TU ]	  U5      $ X R                  L a  g [        U l        [        R                  X5        g r  )r  r  r  r  r   r  )r|  r   r  s     r   r  !MaskedConstant.__array_finalize__  sJ    ##%% 7-c22%%% )DN**45r   c                 J    U R                  [        5      R                  X5      $ r  )ri  r   r  )r|  r   r  r  s       r   r  MaskedConstant.__array_wrap__  s    yy%44SBBr   c                 4    [        [        R                  5      $ r  )r(  r   r_  r  s    r   r  MaskedConstant.__str__  s    &//00r   c                 T    U [         R                  L a  g[        R                  U 5      $ )Nrw   )r]  r  rJ  rs  r  s    r   rs  MaskedConstant.__repr__  s$    >--- ??4((r   c                      [         R                  X5      $ ! [         a3    [        R                  " S[
        SS9  [         R                  U S5      s $ f = f)NzjFormat strings passed to MaskedConstant are ignored, but in future may error or produce different behaviorr  r   r   )rJ  
__format__r   r   r   FutureWarning)r|  format_specs     r   r  MaskedConstant.__format__  sR    		/$$T77 	/MM6!
 $$T2..	/s    :AAc                     U R                   S4$ )z.Override of MaskedArray's __reduce__.
        r   r  r  s    r   r  MaskedConstant.__reduce__  s     ##r   c                     U $ r  r   r  s     r   __iop__MaskedConstant.__iop__  r  r   c                     U $ )z9Copy is a no-op on the maskedconstant, as it is a scalar r   )r|  r  r  s      r   r=   MaskedConstant.copy  s	     r   c                     U $ r  r   r  s    r   __copy__MaskedConstant.__copy__  r  r   c                     U $ r  r   )r|  r  s     r   r  MaskedConstant.__deepcopy__  r  r   c                    > U R                  5       (       d  [        TU ]	  X5      $ X R                  L a  [	        SU < S35      e[        TU ]	  X5      $ )Nzattributes of z are not writeable)r  r  __setattr__r  rh  )r|  attrr@  r  s      r   r   MaskedConstant.__setattr__  sZ    ##%%7&t33%%%  (:;= =
 7&t33r   r  r  )r   r   r   r   r  classmethodr  r  r  r  r  rs  r  r  r  r  r  r  r  r  r  r=   r  r  r   r   r  r  s   @r   r]  r]    s    KL L
$6C1)/$ 	H   
4 
4r   r]  c                     [        XXXXuXUS9$ )zn
Shortcut to MaskedArray.

The options are in a different order for convenience and backwards
compatibility.

)
rl  r  r=   rf  r  r  rM  r  r  r  )r   )rj  r  r=   r  rl  rM  r  r  r  rf  r  s              r   r   r     s"     te"!*"@ @r   c                 Z    [        U 5      nU[        L a  gUR                  5       (       a  gg)a  
Determine whether input has masked values.

Accepts any object as input, but always returns False unless the
input is a MaskedArray containing masked values.

Parameters
----------
x : array_like
    Array to check for masked values.

Returns
-------
result : bool
    True if `x` is a MaskedArray with masked values, False otherwise.

Examples
--------
>>> import numpy as np
>>> import numpy.ma as ma
>>> x = ma.masked_equal([0, 1, 0, 2, 3], 0)
>>> x
masked_array(data=[--, 1, --, 2, 3],
             mask=[ True, False,  True, False, False],
       fill_value=0)
>>> ma.is_masked(x)
True
>>> x = ma.masked_equal([0, 1, 0, 2, 3], 42)
>>> x
masked_array(data=[0, 1, 0, 2, 3],
             mask=False,
       fill_value=42)
>>> ma.is_masked(x)
False

Always returns False if `x` isn't a MaskedArray.

>>> x = [False, True, False]
>>> ma.is_masked(x)
False
>>> x = 'a string'
>>> ma.is_masked(x)
False

FT)rY   r   r!   )r  r   s     r   rg   rg   
  s)    \ 	
AF{	
r   c                   X   ^  \ rS rSrSrU 4S jrS r\R                  4S jr	S r
SrU =r$ )_extrema_operationiE  z
Generic class for maximum/minimum functions.

.. note::
  This is the base class for `_maximum_operation` and
  `_minimum_operation`.

c                 <   > [         TU ]  U5        X l        X0l        g r  )r  r}  r  fill_value_func)r|  r  r  rM  r  s       r   r}  _extrema_operation.__init__N  s    )r   c                 8    [        U R                  X5      X5      $ )r  )r   r  r{  s      r   r  _extrema_operation.__call__S  s     T\\!'..r   c                    [        USSS9n[        U5      nU[        R                  L aG  UR                  S:  a7  [
        R                  " SU R                   SU R                   S3[        SS	9  SnU[        R                  La
  [        US
9nO
[        5       nU[        L a  U R                  R                  " U40 UD6nU$ UR                  U R                  U5      5      R                  [!        U5      5      nU R                  R                  " U40 UD6n["        R$                  R                  " U40 UD6n['        US5      (       a  X5l        U$ U(       a  [*        nU$ )z#Reduce target along the given axis.NTre  r   z!In the future the default for ma.z:.reduce will be axis=0, not the current None, to match np.z;.reduce. Explicitly pass 0 or None to silence this warning.r  r   r  rn  )r5  rY   r  r
   r   r   r   r   r   r[  r   r   r  rN   r	  ri  r/  r  ro   r   rn  rw   )r|  r  r  r   r  r  s         r   r  _extrema_operation.reduceX  s:   T6FO2;;6;;?MM3DMM? C559]]O DEE )Q	8
 Dr{{"t_FVF;f//A  ]]$$V,..2d4<.@ f//A!!((5f5Aq'""  r   c                 v   [        U5      n[        U5      nU[        L a  U[        L a  [        nO+[        U5      n[        U5      n[        R	                  X45      nU R
                  R	                  [        U5      [        U5      5      n[        U[        5      (       d  UR                  [        5      nXVl
        U$ )z<Return the function applied to the outer product of a and b.)rY   r   rZ   rq   r   r   rN   r  r   ri  rn  )r|  rS  r   r  r  r   rU  s          r   r   _extrema_operation.outerx  s    QZQZ<B&LAaBaB  (AfQi3&+..[[-Fr   )r  r	  )r   r   r   r   r   r}  r  r  r
   r  r   r   r  r  s   @r   r  r  E  s+    *
/
 #%++ @ r   r  c                     U[         R                  L a  0 OSU0n U R                  " SXUS.UD6$ ! [        [        4 a!    [        U 5      R                  " SXUS.UD6s $ f = fNr4  r  rM  r  r   )r  r
   r   rh  r   r/   r   r  r  rM  r4  r  s         r   r   r     v    r{{*RX0FF6wwKDSKFKKI& 6 #"" 6'*6.46 	66   0 .A! A!c                     U[         R                  L a  0 OSU0n U R                  " SXUS.UD6$ ! [        [        4 a!    [        U 5      R                  " SXUS.UD6s $ f = fr  )r  r
   r   rh  r   r/   r  s         r   r   r     r  r  c                     U[         R                  L a  0 OSU0n U R                  " U4X#S.UD6$ ! [        [        4 a!    [        U 5      R                  " SXUS.UD6s $ f = f)Nr4  )r  rM  r  r   )r  r
   r   rh  r   r/   r  s         r   r   r     sv    r{{*RX0FF6wwtFFvFFI& 6 #"" 6'*6.46 	66r  c                   .    \ rS rSrSrSS jrS rS rSrg)	_frommethodi  z
Define functions from existing MaskedArray methods.

Parameters
----------
methodname : str
    Name of the method to transform.

c                 R    Xl         Xl        U R                  5       U l        X l        g r  )r   r   getdocr   reversed)r|  
methodnamer  s      r   r}  _frommethod.__init__  s    "&{{} r   c                     [        [        U R                  S5      =(       d    [        [        U R                  S5      nU R                  [	        U5      -   nUb  SU< S[        USS5      < 3nU$ g)<Return the doc of the function (from the doc of the method).Nz    rT  r   )r  r   r   r  r   )r|  meth	signaturedocs       r   r  _frommethod.getdoc  se    {DMM48 -Bt, 	MM$8$>>	74D9;CJ r   c                     U R                   (       a  [        U5      nUS   UsoS'   [        U5      nU R                  n[	        [        U5      US 5      nUc  [	        [        U5      nU" U/UQ70 UD6$ r  )r  rs  r/   r   r  r/  r  )r|  rS  r  r  marrmethod_namemethods          r   r  _frommethod.__call__  sm    ==:Da!JAAw!}mmd[$7>R-Fd,T,V,,r   )r   r   r   r  Nr  )	r   r   r   r   r   r}  r  r  r   r   r   r   r  r    s    !-r   r  r   r   r!   r8   )r  rB   rC   r=   rF   r]   r`   r   r   r   r   r   rV  r   r   r   r   r   r   rA   c                 8    [        U 5      n U R                  XX4S9$ )z

    )r  r  r  )rx   r   )rS  ra   r  r  r  s        r   r   r     s      	QA66'#699r   c           	      ~   Ub  [        S5      e[        U 5      n[        U5      n[        X45      n[        U 5      n[        U5      n[	        U [
        5      (       a  [        U 5      nO[
        n[        R                  " SSS9   [        R                  " XV[        R                  " Xg5      5      R                  U5      n	SSS5        W	R                  U 5        [        R                  " [        R                  " U	R                  [         5      5      5      n
U["        La2  U	R$                  (       d  [&        $ [        R(                  " XZ5      U	l        U
R-                  5       (       aI  U	R$                  (       d  [&        $ U	R*                  ["        L a  Xl        U	R.                  U	R0                  U
'   U	$ ! , (       d  f       N= f)aR  
Returns element-wise base array raised to power from second array.

This is the masked array version of `numpy.power`. For details see
`numpy.power`.

See Also
--------
numpy.power

Notes
-----
The *out* argument to `numpy.power` is not supported, `third` has to be
None.

Examples
--------
>>> import numpy as np
>>> import numpy.ma as ma
>>> x = [11.2, -3.973, 0.801, -1.41]
>>> mask = [0, 0, 0, 1]
>>> masked_x = ma.masked_array(x, mask)
>>> masked_x
masked_array(data=[11.2, -3.973, 0.801, --],
         mask=[False, False, False,  True],
   fill_value=1e+20)
>>> ma.power(masked_x, 2)
masked_array(data=[125.43999999999998, 15.784728999999999,
               0.6416010000000001, --],
         mask=[False, False, False,  True],
   fill_value=1e+20)
>>> y = [-0.5, 2, 0, 17]
>>> masked_y = ma.masked_array(y, mask)
>>> masked_y
masked_array(data=[-0.5, 2.0, 0.0, --],
         mask=[False, False, False,  True],
   fill_value=1e+20)
>>> ma.power(masked_x, masked_y)
masked_array(data=[0.2988071523335984, 15.784728999999999, 1.0, --],
         mask=[False, False, False,  True],
   fill_value=1e+20)

Nz3-argument power not supported.r  r  )r   rY   rv   rX   r  r   r/  r  r  r   r  r   ri  r  rp   rm  r   r   r   rw   rq   rn  r!   rM  rg  )rS  r   thirdr  r  r   fafbr  rU  ro  s              r   r   r     s1   X 9::	B	BA	B	B![!!7	Hh	7!R!45::8D 
8
nnR[[W)=>?G{{M}}Q0{{}}{{M\\V#"L & 1 1WM# 
8	7s   ;F..
F<r,   r+   rX  c          	          [         R                  " U 5      n U[         R                  L a  [        U 5      n[	        U [
        5      (       a  U R                  XX4USS9$ U R                  XUSS9$ )z)Function version of the eponymous method.Nr  r%  r  r]  rM  rY  r  r%  r  rY  )r  r/   r
   r   r  r   r-   rS  r  r%  r  r]  rM  rY  s          r   r-   r-   R  sm     	aA r{{&q)![!!yydU$.t  = 	= yydU4yHHr   r   c          	          [         R                  " U SSS9n Uc  U R                  5       n Sn[        U [        5      (       a  U R                  XX4XVS9  U $ U R                  XX6S9  U $ )a  
Return a sorted copy of the masked array.

Equivalent to creating a copy of the array
and applying the  MaskedArray ``sort()`` method.

Refer to ``MaskedArray.sort`` for the full documentation

See Also
--------
MaskedArray.sort : equivalent method

Examples
--------
>>> import numpy as np
>>> import numpy.ma as ma
>>> x = [11.2, -3.973, 0.801, -1.41]
>>> mask = [0, 0, 0, 1]
>>> masked_x = ma.masked_array(x, mask)
>>> masked_x
masked_array(data=[11.2, -3.973, 0.801, --],
             mask=[False, False, False,  True],
       fill_value=1e+20)
>>> ma.sort(masked_x)
masked_array(data=[-3.973, 0.801, 11.2, --],
             mask=[False, False, False,  True],
       fill_value=1e+20)
Tre  r   r1  r2  )r  r   r{  r  r   r   r3  s          r   r   r   b  sn    < 	T*A|IIK![!!	D5$ 	 	5 H 	
D5@Hr   c                 4    [        U 5      R                  5       $ )a  
Return all the non-masked data as a 1-D array.

This function is equivalent to calling the "compressed" method of a
`ma.MaskedArray`, see `ma.MaskedArray.compressed` for details.

See Also
--------
ma.MaskedArray.compressed : Equivalent method.

Examples
--------
>>> import numpy as np

Create an array with negative values masked:

>>> import numpy as np
>>> x = np.array([[1, -1, 0], [2, -1, 3], [7, 4, -1]])
>>> masked_x = np.ma.masked_array(x, mask=x < 0)
>>> masked_x
masked_array(
  data=[[1, --, 0],
        [2, --, 3],
        [7, 4, --]],
  mask=[[False,  True, False],
        [False,  True, False],
        [False, False,  True]],
  fill_value=999999)

Compress the masked array into a 1-D array of non-masked values:

>>> np.ma.compressed(masked_x)
array([1, 0, 2, 3, 7, 4])

)r/   r9   r  s    r   r9   r9     s    H a=##%%r   c                    [         R                  " U  Vs/ s H  n[        U5      PM     snU5      n[        U 6 nUR	                  U5      nU  H  n[        U5      [        Ld  M    O   U$ [         R                  " U  Vs/ s H  n[        U5      PM     snU5      nUR                  UR                  5      n[        U5      Ul        U$ s  snf s  snf )a  
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 as np
>>> 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)

)r  r:   rX   rc  ri  rY   r   rZ   r   r   r  rn  )r_  r  rS  r  r`  rj  r  dms           r   r:   r:     s    T 	F3Fq
F3T:A'D66$<D1:V#  	&9&Qa&94	@B	AGG	B b!DJK! 4 :s   C>Cc                     [         R                  " X5      R                  [        5      n[	        U 5      [
        La&  [         R                  " U R                  U5      Ul        U$ )a  
Extract a diagonal or construct a diagonal array.

This function is the equivalent of `numpy.diag` that takes masked
values into account, see `numpy.diag` for details.

See Also
--------
numpy.diag : Equivalent function for ndarrays.

Examples
--------
>>> import numpy as np

Create an array with negative values masked:

>>> import numpy as np
>>> x = np.array([[11.2, -3.973, 18], [0.801, -1.41, 12], [7, 33, -12]])
>>> masked_x = np.ma.masked_array(x, mask=x < 0)
>>> masked_x
masked_array(
  data=[[11.2, --, 18.0],
        [0.801, --, 12.0],
        [7.0, 33.0, --]],
  mask=[[False,  True, False],
        [False,  True, False],
        [False, False,  True]],
  fill_value=1e+20)

Isolate the main diagonal from the masked array:

>>> np.ma.diag(masked_x)
masked_array(data=[11.2, --, --],
             mask=[False,  True,  True],
       fill_value=1e+20)

Isolate the first diagonal below the main diagonal:

>>> np.ma.diag(masked_x, -1)
masked_array(data=[0.801, 33.0],
             mask=[False, False],
       fill_value=1e+20)

)r  rE   ri  r   rY   r   rn  )r  r[  rF  s      r   rE   rE     sD    Z WWQ],Fqzwwqww*Mr   c                     [        U 5      nU[        L a+  [        R                  " [	        U 5      U5      n[        U5      $ [        R                  " [	        U S5      U5      n[        X2S9$ )a  
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

Examples
--------
Shift with a masked array:

>>> arr = np.ma.array([10, 20, 30], mask=[False, True, False])
>>> np.ma.left_shift(arr, 1)
masked_array(data=[20, --, 60],
             mask=[False,  True, False],
       fill_value=999999)

Large shift:

>>> np.ma.left_shift(10, 10)
masked_array(data=10240,
             mask=False,
       fill_value=999999)

Shift with a scalar and an array:

>>> scalar = 10
>>> arr = np.ma.array([1, 2, 3], mask=[False, True, False])
>>> np.ma.left_shift(scalar, arr)
masked_array(data=[20, --, 80],
             mask=[False,  True, False],
       fill_value=999999)


r   r  )rY   r   r  ri   rN   rx   rS  r  r   r  s       r   ri   ri   $  sX    N 	
AF{VAY*AVAq\1-A&&r   c                     [        U 5      nU[        L a+  [        R                  " [	        U 5      U5      n[        U5      $ [        R                  " [	        U S5      U5      n[        X2S9$ )aH  
Shift the bits of an integer to the right.

This is the masked array version of `numpy.right_shift`, for details
see that function.

See Also
--------
numpy.right_shift

Examples
--------
>>> import numpy as np
>>> import numpy.ma as ma
>>> x = [11, 3, 8, 1]
>>> mask = [0, 0, 0, 1]
>>> masked_x = ma.masked_array(x, mask)
>>> masked_x
masked_array(data=[11, 3, 8, --],
             mask=[False, False, False,  True],
       fill_value=999999)
>>> ma.right_shift(masked_x,1)
masked_array(data=[5, 1, 4, --],
             mask=[False, False, False,  True],
       fill_value=999999)

r   r  )rY   r   r  r   rN   rx   r:  s       r   r   r   T  sW    8 	
AF{fQi+AfQlA.A&&r   c                      U R                  XUS9$ ! [         a'    [        R                  " U 5      R                  XUS9s $ f = f)a  
Set storage-indexed locations to corresponding values.

This function is equivalent to `MaskedArray.put`, see that method
for details.

See Also
--------
MaskedArray.put

Examples
--------
Putting values in a masked array:

>>> a = np.ma.array([1, 2, 3, 4], mask=[False, True, False, False])
>>> np.ma.put(a, [1, 3], [10, 30])
>>> a
masked_array(data=[ 1, 10,  3, 30],
             mask=False,
       fill_value=999999)

Using put with a 2D array:

>>> b = np.ma.array([[1, 2], [3, 4]], mask=[[False, True], [False, False]])
>>> np.ma.put(b, [[0, 1], [1, 0]], [[10, 20], [30, 40]])
>>> b
masked_array(
  data=[[40, 30],
        [ 3,  4]],
  mask=False,
  fill_value=999999)

r  )r   rh  r  r0   )rS  ra   r  r  s       r   r   r   y  sH    F=uuW4u00 =zz!}  t <<=s    .AAc                    [        U [        5      (       d  U R                  [        5      n [        U5      [	        U5      pC[	        U 5      [
        L aU  U[
        LaK  SU l        [        U R                  U R                  5      U l
        [        R                  " U R                  XAS9  OU R                  (       aN  U[
        LaD  U R                  R                  5       n[        R                  " XTUS9  U =R                  U-  sl        O3U[
        L a  [!        U5      n[        R                  " U R                  XAS9  [        R                  " U R"                  X1S9  g)ax  
Changes elements of an array based on conditional and input values.

This is the masked array version of `numpy.putmask`, for details see
`numpy.putmask`.

See Also
--------
numpy.putmask

Notes
-----
Using a masked array as `values` will **not** transform a `ndarray` into
a `MaskedArray`.

Examples
--------
>>> import numpy as np
>>> arr = [[1, 2], [3, 4]]
>>> mask = [[1, 0], [0, 0]]
>>> x = np.ma.array(arr, mask=mask)
>>> np.ma.putmask(x, x < 4, 10*x)
>>> x
masked_array(
  data=[[--, 20],
        [30, 4]],
  mask=[[ True, False],
        [False, False]],
  fill_value=999999)
>>> x.data
array([[10, 20],
       [30,  4]])

Tr  N)r  r   ri  rX   rY   r   r  ru   r   r  rn  r  r  r  r=   rl  rZ   rg  )rS  rl  r  valdatavalmaskr   s         r   r   r     s    H a%%FF;!&/76?gqzV&  AM$QWWagg6AGIIaggw3	
& AIIa-FFaKFf"6*G
		!''7/IIaggw+
r   c                      U R                  U5      $ ! [         a;    [        R                  " U 5      R                  U5      R	                  [
        5      s $ f = f)a;  
Permute the dimensions of an array.

This function is exactly equivalent to `numpy.transpose`.

See Also
--------
numpy.transpose : Equivalent function in top-level NumPy module.

Examples
--------
>>> import numpy as np
>>> 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   rh  r  r0   ri  r   )rS  r  s     r   r   r     sJ    B?{{4   ?zz!}&&t,11+>>?s    AAAc                      U R                  XS9$ ! [         a;    [        R                  " U 5      R                  XS9nUR	                  [
        5      s $ f = f)a  
Returns an array containing the same data with a new shape.

Refer to `MaskedArray.reshape` for full documentation.

See Also
--------
MaskedArray.reshape : equivalent function

Examples
--------
Reshaping a 1-D array:

>>> a = np.ma.array([1, 2, 3, 4])
>>> np.ma.reshape(a, (2, 2))
masked_array(
  data=[[1, 2],
        [3, 4]],
  mask=False,
  fill_value=999999)

Reshaping a 2-D array:

>>> b = np.ma.array([[1, 2], [3, 4]])
>>> np.ma.reshape(b, (1, 4))
masked_array(data=[[1, 2, 3, 4]],
             mask=False,
       fill_value=999999)

Reshaping a 1-D array with a mask:

>>> c = np.ma.array([1, 2, 3, 4], mask=[False, True, False, False])
>>> np.ma.reshape(c, (2, 2))
masked_array(
  data=[[1, --],
        [3, 4]],
  mask=[[False,  True],
        [False, False]],
  fill_value=999999)

r  )r   rh  r  r0   ri  r   )rS  	new_shaper  _tmps       r   r   r     sR    V&yyy00 &zz!}$$Y$<yy%%&s    AAAc                     [        U 5      nU[        La  [        R                  " X!5      n[        R                  " X5      R	                  [        U 5      5      nUR                  (       a  X#l        U$ )a  
Return a new masked array with the specified size and shape.

This is the masked equivalent of the `numpy.resize` function. The new
array is filled with repeated copies of `x` (in the order that the
data are stored in memory). If `x` is masked, the new array will be
masked, and the new mask will be a repetition of the old one.

See Also
--------
numpy.resize : Equivalent function in the top level NumPy module.

Examples
--------
>>> import numpy as np
>>> import numpy.ma as ma
>>> a = ma.array([[1, 2] ,[3, 4]])
>>> a[0, 1] = ma.masked
>>> a
masked_array(
  data=[[1, --],
        [3, 4]],
  mask=[[False,  True],
        [False, False]],
  fill_value=999999)
>>> np.resize(a, (3, 3))
masked_array(
  data=[[1, 2, 3],
        [4, 1, 2],
        [3, 4, 1]],
  mask=False,
  fill_value=999999)
>>> ma.resize(a, (3, 3))
masked_array(
  data=[[1, --, 3],
        [4, 1, --],
        [3, 4, 1]],
  mask=[[False,  True, False],
        [False, False,  True],
        [False, False, False]],
  fill_value=999999)

A MaskedArray is always returned, regardless of the input type.

>>> a = np.array([[1, 2] ,[3, 4]])
>>> ma.resize(a, (3, 3))
masked_array(
  data=[[1, 2, 3],
        [4, 1, 2],
        [3, 4, 1]],
  mask=False,
  fill_value=999999)

)rY   r   r  r   ri  rc  r   rn  )r  rB  r   rU  s       r   r   r   4  sS    p 	
AIIa#YYq$))*=a*@AF{{Mr   c                 @    [         R                  " [        U 5      5      $ )z-
maskedarray version of the numpy function.

)r  r   rX   r!  s    r   r   r   u  s    
 7773<  r   c                 @    [         R                  " [        U 5      5      $ *maskedarray version of the numpy function.)r  r   rX   r!  s    r   r   r     s    88GCL!!r   c                 B    [         R                  " [        U 5      U5      $ rG  )r  r   rX   )r   r  s     r   r   r     s    7773<&&r   c                   US:X  a  U $ US:  a  [        S[        U5      -   5      e[        R                  R	                  U 5      n U R
                  S:X  a  [        S5      e/ nU[        R                  Lay  [        R                  R	                  U5      nUR
                  S:X  a9  [        U R                  5      nSXb'   [        R                  " U[        U5      5      nUR                  U5        UR                  U 5        U[        R                  Lay  [        R                  R	                  U5      nUR
                  S:X  a9  [        U R                  5      nSXb'   [        R                  " U[        U5      5      nUR                  U5        [        U5      S:  a  [        R                  R                  XR5      n [        R                  " XU5      $ )a  
Calculate the n-th discrete difference along the given axis.
The first difference is given by ``out[i] = a[i+1] - a[i]`` along
the given axis, higher differences are calculated by using `diff`
recursively.
Preserves the input mask.

Parameters
----------
a : array_like
    Input array
n : int, optional
    The number of times values are differenced. If zero, the input
    is returned as-is.
axis : int, optional
    The axis along which the difference is taken, default is the
    last axis.
prepend, append : array_like, optional
    Values to prepend or append to `a` along axis prior to
    performing the difference.  Scalar values are expanded to
    arrays with length 1 in the direction of axis and the shape
    of the input array in along all other axes.  Otherwise the
    dimension and shape must match `a` except along axis.

Returns
-------
diff : MaskedArray
    The n-th differences. The shape of the output is the same as `a`
    except along `axis` where the dimension is smaller by `n`. The
    type of the output is the same as the type of the difference
    between any two elements of `a`. This is the same as the type of
    `a` in most cases. A notable exception is `datetime64`, which
    results in a `timedelta64` output array.

See Also
--------
numpy.diff : Equivalent function in the top-level NumPy module.

Notes
-----
Type is preserved for boolean arrays, so the result will contain
`False` when consecutive elements are the same and `True` when they
differ.

For unsigned integer arrays, the results will also be unsigned. This
should not be surprising, as the result is consistent with
calculating the difference directly:

>>> u8_arr = np.array([1, 0], dtype=np.uint8)
>>> np.ma.diff(u8_arr)
masked_array(data=[255],
             mask=False,
       fill_value=np.uint64(999999),
            dtype=uint8)
>>> u8_arr[1,...] - u8_arr[0,...]
np.uint8(255)

If this is not desirable, then the array should be cast to a larger
integer type first:

>>> i16_arr = u8_arr.astype(np.int16)
>>> np.ma.diff(i16_arr)
masked_array(data=[-1],
             mask=False,
       fill_value=np.int64(999999),
            dtype=int16)

Examples
--------
>>> import numpy as np
>>> a = np.array([1, 2, 3, 4, 7, 0, 2, 3])
>>> x = np.ma.masked_where(a < 2, a)
>>> np.ma.diff(x)
masked_array(data=[--, 1, 1, 3, --, --, 1],
        mask=[ True, False, False, False,  True,  True, False],
    fill_value=999999)

>>> np.ma.diff(x, n=2)
masked_array(data=[--, 0, 2, --, --, --],
            mask=[ True, False, False,  True,  True,  True],
    fill_value=999999)

>>> a = np.array([[1, 3, 1, 5, 10], [0, 1, 5, 6, 8]])
>>> x = np.ma.masked_equal(a, value=1)
>>> np.ma.diff(x)
masked_array(
    data=[[--, --, --, 5],
            [--, --, 1, 2]],
    mask=[[ True,  True,  True, False],
            [ True,  True, False, False]],
    fill_value=1)

>>> np.ma.diff(x, axis=0)
masked_array(data=[[--, --, --, 1, -2]],
        mask=[[ True,  True,  True, False, False]],
    fill_value=1)

r   z#order must be non-negative but got z4diff requires input that is at least one dimensionalr   )rI  rd  r  r  r/   r   r
   rs  r   r~  r  r"   r<  r:   rG   )rS  r  r  prependr"   combinedr   s          r   rG   rG     sb   F 	Av1u>aHII
Avv{B 	 Hbkk!%%""7+<<1MEEKooguU|<G OOAR[[ !!&);;!MEEK__VU5\:F
8}qEEh- 771r   c                 :   U[         L U[         L 4R                  S5      nUS:X  a  [        S5      eUS:X  a  [        U 5      $ [	        U S5      n[        U5      n[        U5      n[        U 5      n[        U5      n[        U5      n	U[        L aH  U[        La?  [        R                  " SUR                  S9n[        R                  " SU	R                  S9nOPU[        L aG  U[        La>  [        R                  " SUR                  S9n[        R                  " SUR                  S9n	[        R                  " XEU5      n
[        R                  " XHU	5      n[        R                  " U[        R                  " SUR                  S9U5      n[        U5      n[        XS9$ )	a   
Return a masked array with elements from `x` or `y`, depending on condition.

.. note::
    When only `condition` is provided, this function is identical to
    `nonzero`. The rest of this documentation covers only the case where
    all three arguments are provided.

Parameters
----------
condition : array_like, bool
    Where True, yield `x`, otherwise yield `y`.
x, y : array_like, optional
    Values from which to choose. `x`, `y` and `condition` need to be
    broadcastable to some shape.

Returns
-------
out : MaskedArray
    An masked array with `masked` elements where the condition is masked,
    elements from `x` where `condition` is True, and elements from `y`
    elsewhere.

See Also
--------
numpy.where : Equivalent function in the top-level NumPy module.
nonzero : The function that is called when x and y are omitted

Examples
--------
>>> import numpy as np
>>> x = np.ma.array(np.arange(9.).reshape(3, 3), mask=[[0, 1, 0],
...                                                    [1, 0, 1],
...                                                    [0, 1, 0]])
>>> x
masked_array(
  data=[[0.0, --, 2.0],
        [--, 4.0, --],
        [6.0, --, 8.0]],
  mask=[[False,  True, False],
        [ True, False,  True],
        [False,  True, False]],
  fill_value=1e+20)
>>> np.ma.where(x > 5, x, -3.1416)
masked_array(
  data=[[-3.1416, --, -3.1416],
        [--, -3.1416, --],
        [6.0, --, 8.0]],
  mask=[[False,  True, False],
        [ True, False,  True],
        [False,  True, False]],
  fill_value=1e+20)

Tr   z)Must provide both 'x' and 'y' or neither.r  Fr   r  r  )r
   rA   rI  r   rN   rX   rZ   rw   r  r   r  r   r   r  rx   )r:  r  r/  missingr  xdydcmxmymrj  rl  s               r   r   r     sI   r H}a8m,2248G!|DEE!|y!! 
	5	!B	B	B 
i	 B	aB	aB 	F{qXXb)WWR)	
f&XXb)WWR)88BBD88BBD88B$**5t<D D((r   c                    S nS n[        U S5      nU Vs/ s H
  ou" U5      PM     nnU Vs/ s H
  ot" U5      PM     n	n[        R                  " XhUS9n
[        [	        U
[        U 5      5      SSS9n
[        R                  " XiX2S9R                  [        5      nUb(  [        U[        5      (       a  UR                  U
5        U$ UR                  U
5        U$ s  snf s  snf )	a  
Use an index array to construct a new array from a list of choices.

Given an array of integers and a list of n choice arrays, this method
will create a new array that merges each of the choice arrays.  Where a
value in `index` is i, the new array will have the value that choices[i]
contains in the same place.

Parameters
----------
indices : ndarray of ints
    This array must contain integers in ``[0, n-1]``, where n is the
    number of choices.
choices : sequence of arrays
    Choice arrays. The index array and all of the choices should be
    broadcastable to the same shape.
out : array, optional
    If provided, the result will be inserted into this array. It should
    be of the appropriate shape and `dtype`.
mode : {'raise', 'wrap', 'clip'}, optional
    Specifies how out-of-bounds indices will behave.

    * 'raise' : raise an error
    * 'wrap' : wrap around
    * 'clip' : clip to the range

Returns
-------
merged_array : array

See Also
--------
choose : equivalent function

Examples
--------
>>> import numpy as np
>>> 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)

c                 ,    U [         L a  g[        U 5      $ )z,Returns the filled array, or True if masked.T)rw   rN   r  s    r   fmaskchoose.<locals>.fmask  s    ;ayr   c                 ,    U [         L a  g[        U 5      $ )z:Returns the mask, True if ``masked``, False if ``nomask``.T)rw   rY   r  s    r   nmaskchoose.<locals>.nmask  s    ;qzr   r   r  FTr#  )r  r  )
rN   r  r5   rs   rv   rY   ri  r   r  r  )ra   choicesr  r  rV  rY  r   r  masksrj  
outputmaskr  s               r   r5   r5   t  s    \ 	wA&'w!U1XwE'%&gE!HgD&1$/J7:ww/?@ %d4J 			!.33K@A
c;''OOJ'
MM*H (&s
   CCc                     Uc  [         R                  " XU5      $ [         R                  " [        U 5      X5        [        US5      (       a  [	        U 5      Ul        U$ )a,  
Return a copy of a, rounded to 'decimals' places.

When 'decimals' is negative, it specifies the number of positions
to the left of the decimal point.  The real and imaginary parts of
complex numbers are rounded separately. Nothing is done if the
array is not of float type and 'decimals' is greater than or equal
to 0.

Parameters
----------
decimals : int
    Number of decimals to round to. May be negative.
out : array_like
    Existing array to use for output.
    If not given, returns a default copy of a.

Notes
-----
If out is given and does not have a mask attribute, the mask of a
is lost!

Examples
--------
>>> import numpy as np
>>> import numpy.ma as ma
>>> x = [11.2, -3.973, 0.801, -1.41]
>>> mask = [0, 0, 0, 1]
>>> masked_x = ma.masked_array(x, mask)
>>> masked_x
masked_array(data=[11.2, -3.973, 0.801, --],
             mask=[False, False, False, True],
    fill_value=1e+20)
>>> ma.round_(masked_x)
masked_array(data=[11.0, -4.0, 1.0, --],
             mask=[False, False, False, True],
    fill_value=1e+20)
>>> ma.round(masked_x, decimals=1)
masked_array(data=[11.2, -4.0, 0.8, --],
             mask=[False, False, False, True],
    fill_value=1e+20)
>>> ma.round_(masked_x, decimals=-1)
masked_array(data=[10.0, -0.0, 0.0, --],
             mask=[False, False, False, True],
    fill_value=1e+20)
rn  )r  r   rX   r   rY   rn  )rS  rV  r  s      r   r   r     sJ    ^ {xxS))
X+3  
CI
r   c                 6   [        U SS9n [        U 5      nU[        L d  UR                  5       (       a  Uc  U $ U R                  R                  5       U l        [        XR                  5      nU H&  nU =R                  UR                  USS9-  sl        M(     U $ )z@
Mask whole 1-d vectors of an array that contain masked values.
Fry  T)r  r4  )r   rY   r   r!   rn  r=   r   r   )rS  r  r   r  r  s        r   _mask_propagater`    s|     	auA
AF{!%%''T\ggllnAGff-D	155b4500 Hr   c                 p   USL a  [         R                  " U 5      S:X  d  [         R                  " U5      S:X  a  OqUR                  S:X  a1  [        X R                  S-
  5      n [        XR                  S-
  5      nO0[        X R                  S-
  5      n [        XR                  S-
  5      n[        U 5      ) n[        U5      ) nUc  [         R                  " [        U S5      [        US5      5      n[         R                  " XE5      ) n[         R                  " U5      S:X  a  [         R                  " U5      nUR                  [        X5      5      nUR                  U5        U$ [         R                  " [        U S5      [        US5      UR                  5      nUR                  R                  UR                  :w  a*  [         R                  " UR                  [        5      Ul        [         R                  " XEUR                  5        [         R                   " UR                  UR                  5        U$ )a  
Return the dot product of two arrays.

This function is the equivalent of `numpy.dot` that takes masked values
into account. Note that `strict` and `out` are in different position
than in the method version. In order to maintain compatibility with the
corresponding method, it is recommended that the optional arguments be
treated as keyword only.  At some point that may be mandatory.

Parameters
----------
a, b : masked_array_like
    Inputs arrays.
strict : bool, optional
    Whether masked data are propagated (True) or set to 0 (False) for
    the computation. Default is False.  Propagating the mask means that
    if a masked value appears in a row or column, the whole row or
    column is considered masked.
out : masked_array, optional
    Output argument. This must have the exact kind that would be returned
    if it was not used. In particular, it must have the right type, must be
    C-contiguous, and its dtype must be the dtype that would be returned
    for `dot(a,b)`. This is a performance feature. Therefore, if these
    conditions are not met, an exception is raised, instead of attempting
    to be flexible.

See Also
--------
numpy.dot : Equivalent function for ndarrays.

Examples
--------
>>> import numpy as np
>>> a = np.ma.array([[1, 2, 3], [4, 5, 6]], mask=[[1, 0, 0], [0, 0, 0]])
>>> b = np.ma.array([[1, 2], [3, 4], [5, 6]], mask=[[1, 0], [0, 0], [0, 0]])
>>> np.ma.dot(a, b)
masked_array(
  data=[[21, 26],
        [45, 64]],
  mask=[[False, False],
        [False, False]],
  fill_value=999999)
>>> np.ma.dot(a, b, strict=True)
masked_array(
  data=[[--, --],
        [--, 64]],
  mask=[[ True,  True],
        [ True, False]],
  fill_value=999999)

Tr   r   r  )r  r   r`  rZ   r-  rN   r0   ri  rc  r  rg  rl  r   rI   r   rn  rp   )	rS  r   r,  r  ambmr  r   r
  s	            r   r-  r-     s   h ~771:?bggajAoVVq[66A:.A66A:.A66A:.A66A:.A
q/	B
q/	B
{FF6!Q<1.VVB^O771:?

1AFF&q,-	aFF6!Q<1syy988>>QWW$(3CI
rsyy!
syy#)),
r   c                     [        U S5      n[        US5      nUR                  S:X  a  SUl        UR                  S:X  a  SUl        [        R                  " X#5      R                  [        5      $ )z
Returns the inner product of a and b for arrays of floating point types.

Like the generic NumPy equivalent the product sum is over the last dimension
of a and b. The first argument is not conjugated.

r   r  )rN   r   r   r  rb   ri  r   )rS  r   r.  r/  s       r   rb   rb   \   sX     
1B	1B	ww!|	ww!|88B  --r   z Masked values are replaced by 0.c                    [        U S5      R                  5       n[        US5      R                  5       n[        R                  " X#5      n[	        U 5      n[	        U5      nU[
        L a  U[
        L a  [        U5      $ [        U 5      n[        U5      n[        S[        R                  " SU-
  SU-
  5      -
  SS9n[        XGS9$ )rH  r   r   Fr  r  )	rN   r   r  r   rY   r   rx   rZ   rs   )rS  r   r.  r/  r  r  r  r   s           r   r   r   p   s    	1			B	1			B
A	B	B	V|fA	aB	aB!bhhq2vq2v..U;A""r   c                    U(       a  U " [        U5      [        R                  " [        R                  " U5      [        S9US9U " [        R                  " [        R                  " U5      [        S9[        U5      US9-  nU " [        U5      [        U5      US9nO9U " [        U5      ) [        U5      ) US9) nU " [        US5      [        US5      US9n[        XeS9$ )z2
Helper function for ma.correlate and ma.convolve
r  r  r   r  )rZ   r  r   r   r  rX   rN   rx   )r   rS  r  r  propagate_maskrl  rj  s          r   _convolve_or_correlaterh     s      l1orwwrxx{$?dKbggbhhqk.QdKL 	 WQZd3 <?"\!_$44@@1va|$7((r   c                 8    [        [        R                  XX#5      $ )a  
Cross-correlation of two 1-dimensional sequences.

Parameters
----------
a, v : array_like
    Input sequences.
mode : {'valid', 'same', 'full'}, optional
    Refer to the `np.convolve` docstring.  Note that the default
    is 'valid', unlike `convolve`, which uses 'full'.
propagate_mask : bool
    If True, then a result element is masked if any masked element contributes towards it.
    If False, then a result element is only masked if no non-masked element
    contribute towards it

Returns
-------
out : MaskedArray
    Discrete cross-correlation of `a` and `v`.

See Also
--------
numpy.correlate : Equivalent function in the top-level NumPy module.

Examples
--------
Basic correlation:

>>> a = np.ma.array([1, 2, 3])
>>> v = np.ma.array([0, 1, 0])
>>> np.ma.correlate(a, v, mode='valid')
masked_array(data=[2],
             mask=[False],
       fill_value=999999)

Correlation with masked elements:

>>> a = np.ma.array([1, 2, 3], mask=[False, True, False])
>>> v = np.ma.array([0, 1, 0])
>>> np.ma.correlate(a, v, mode='valid', propagate_mask=True)
masked_array(data=[--],
             mask=[ True],
       fill_value=999999,
            dtype=int64)

Correlation with different modes and mixed array types:

>>> a = np.ma.array([1, 2, 3])
>>> v = np.ma.array([0, 1, 0])
>>> np.ma.correlate(a, v, mode='full')
masked_array(data=[0, 1, 2, 3, 0],
             mask=[False, False, False, False, False],
       fill_value=999999)

)rh  r  r>   rS  r  r  rg  s       r   r>   r>      s    p "",,dKKr   c                 8    [        [        R                  XX#5      $ )az  
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.
)rh  r  r<   rj  s       r   r<   r<      s    2 ""++qTJJr   c                    [        [        U 5      [        U5      5      nU[        L a<  [        U 5      n[        U5      n[        R
                  " XE5      nUR                  5       $ U(       aV  [        U 5      n[        U5      n[        R
                  " XE5      n[        XcSS9nUR                  S5      R                  S5      $ g)a  
Return True if all entries of a and b are equal, using
fill_value as a truth value where either or both are masked.

Parameters
----------
a, b : array_like
    Input arrays to compare.
fill_value : bool, optional
    Whether masked values in a or b are considered equal (True) or not
    (False).

Returns
-------
y : bool
    Returns True if the two arrays are equal within the given
    tolerance, False otherwise. If either array contains NaN,
    then False is returned.

See Also
--------
all, any
numpy.ma.allclose

Examples
--------
>>> import numpy as np
>>> a = np.ma.array([1e10, 1e-7, 42.0], mask=[0, 0, 1])
>>> a
masked_array(data=[10000000000.0, 1e-07, --],
             mask=[False, False,  True],
       fill_value=1e+20)

>>> b = np.array([1e10, 1e-7, -42.0])
>>> b
array([  1.00000000e+10,   1.00000000e-07,  -4.20000000e+01])
>>> np.ma.allequal(a, b, fill_value=False)
False
>>> np.ma.allequal(a, b)
True

F)rl  r=   TN)	rv   rY   r   rX   r  rK   r   r   rN   )rS  r   rM  r   r  r/  r  r7  s           r   r   r      s    V 	
GAJ'AF{AJAJKKuuw	AJAJKK15)yy""4((r   c           
         [        U SS9n[        USS9nUR                  R                  S:w  a1  [        R                  " US5      nUR                  U:w  a
  [        XgSS9n[        [        U5      [        U5      5      n[        R                  " [        USUS95      R                  S5      n	[        R                  " U	[        [        R                  " U5      S5      :H  5      (       d  g[        R                  " U	5      (       dE  [        [        [        XV-
  5      XC[        U5      -  -   5      U5      n
[        R                  " U
5      $ [        R                  " [        XY   Xi   :H  U5      5      (       d  gXY)    nXi)    n[        [        [        XV-
  5      XC[        U5      -  -   5      U5      n
[        R                  " U
5      $ )a{  
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
--------
>>> import numpy as np
>>> a = np.ma.array([1e10, 1e-7, 42.0], mask=[0, 0, 1])
>>> a
masked_array(data=[10000000000.0, 1e-07, --],
             mask=[False, False,  True],
       fill_value=1e+20)
>>> b = np.ma.array([1e10, 1e-8, -42.0], mask=[0, 0, 1])
>>> np.ma.allclose(a, b)
False

>>> a = np.ma.array([1e10, 1e-8, 42.0], mask=[0, 0, 1])
>>> b = np.ma.array([1.00001e10, 1e-9, -42.0], mask=[0, 0, 1])
>>> np.ma.allclose(a, b)
True
>>> np.ma.allclose(a, b, masked_equal=False)
False

Masked values are not compared directly.

>>> a = np.ma.array([1e10, 1e-8, 42.0], mask=[0, 0, 1])
>>> b = np.ma.array([1.00001e10, 1e-9, 42.0], mask=[0, 0, 1])
>>> np.ma.allclose(a, b)
True
>>> np.ma.allclose(a, b, masked_equal=False)
False

Fr  r   r  )r  r=   )r=   rl  )rx   r  r%  r  result_typerv   rY   isinfrN   r   r!   rk   r   )rS  r   ry   rR  rQ  r  r/  r  r   xinfr  s              r   r   r   '!  sb   R 	QU#AQU#A 	ww||sq"%77eQ%8A
GAJ'A88LQ78??FD66$&!e445566$<<:hquotXa[6H/HI!vvay66&AG+\:;;	%A	%Az(15/4!2D+DE	A 66!9r   c           	      2    U=(       d    Sn[        XSSSUS9$ )ao  
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
--------
>>> import numpy as np
>>> 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))
<class 'numpy.ma.MaskedArray'>

r  FT)r  r=   r  rf  r  rx   )rS  r  r  s      r   r0   r0   !  s&    Z LSEUd#52 2r   c                 l    [        U [        5      (       a  Ub  XR                  :X  a  U $ [        XSSSS9$ )a  
Convert the input to a masked array, conserving subclasses.

If `a` is a subclass of `MaskedArray`, its class is conserved.
No copy is performed if the input is already an `ndarray`.

Parameters
----------
a : array_like
    Input data, in any form that can be converted to an array.
dtype : dtype, optional
    By default, the data-type is inferred from the input data.
order : {'C', 'F'}, optional
    Whether to use row-major ('C') or column-major ('FORTRAN') memory
    representation.  Default is 'C'.

Returns
-------
out : MaskedArray
    MaskedArray interpretation of `a`.

See Also
--------
asarray : Similar to `asanyarray`, but does not conserve subclass.

Examples
--------
>>> import numpy as np
>>> 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))
<class 'numpy.ma.MaskedArray'>

FT)r  r=   r  rf  )r  r   r  rx   )rS  r  s     r   r/   r/   !  s5    Z ![!!u}8HUd$OOr   r   c                     [        S5      e)Nz1fromfile() not yet implemented for a MaskedArray.r  )filer  rA   r  s       r   fromfilerv  !  s    
;= =r   c                 "    [        U S   U S   S9$ )a*  
Build a masked array from a suitable flexible-type array.

The input array has to have a data-type with ``_data`` and ``_mask``
fields. This type of array is output by `MaskedArray.toflex`.

Parameters
----------
fxarray : ndarray
    The structured input array, containing ``_data`` and ``_mask``
    fields. If present, other fields are discarded.

Returns
-------
result : MaskedArray
    The constructed masked array.

See Also
--------
MaskedArray.toflex : Build a flexible-type array from a masked array.

Examples
--------
>>> import numpy as np
>>> 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', '<i8'), ('_mask', '?')])
>>> 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', '<i4'), ('_mask', '|b1'), ('field3', '<f4')]
>>> rec2 = np.zeros((2, 2), dtype=dt)
>>> rec2
array([[(0, False, 0.), (0, False, 0.)],
       [(0, False, 0.), (0, False, 0.)]],
      dtype=[('_data', '<i4'), ('_mask', '?'), ('field3', '<f4')])
>>> y = np.ma.fromflex(rec2)
>>> y
masked_array(
  data=[[0, 0],
        [0, 0]],
  mask=[[False, False],
        [False, False]],
  fill_value=np.int64(999999),
  dtype=int32)

rg  rn  r  rr  )fxarrays    r   rV   rV   "  s    | (ww/?@@r   c                   8    \ rS rSrSrSrS	S jrS rS rS rSr	g)
_convert2maiC"  z
Convert functions from numpy to numpy.ma.

Parameters
----------
    _methodname : string
        Name of the method to transform.

Nc                 z    [        [        U5      U l        U R                  X#5      U l        U=(       d    0 U l        g r  )r  r  _funcr  r   _extras)r|  r  np_ret	np_ma_retr  s        r   r}  _convert2ma.__init__P"  s+    R*
{{65|r   c                     [        U R                  SS5      n[        U R                  5      nU(       a:  U R                  X1U5      nU(       a  U R                  R                  < U< S3nXC-   nU$ )r!  r   NrT  )r  r|  r   _replace_return_typer   )r|  r~  r  r$  r   s        r   r  _convert2ma.getdocU"  sZ    djj)T2"4::.++CCC"&**"5"5s;)C
r   c                     X!;  aC  [        SU SU SU SU R                  R                   SU R                  R                   S35      eUR                  X#5      $ )a  
Replace documentation of ``np`` function's return type.

Replaces it with the proper type for the ``np.ma`` function.

Parameters
----------
doc : str
    The documentation of the ``np`` method.
np_ret : str
    The return type string of the ``np`` method that we want to
    replace. (e.g. "out : ndarray")
np_ma_ret : str
    The return type string of the ``np.ma`` method.
    (e.g. "out : MaskedArray")
zFailed to replace `z` with `z-`. The documentation string for return type, z(, is not found in the docstring for `np.z`. Fix the docstring for `np.z0` or update the expected string for return type.)r  r|  r   replace)r|  r$  r~  r  s       r   r   _convert2ma._replace_return_typea"  sw    " %fXXi[ A==CH E226**2E2E1F G--1ZZ-@-@,A B>>  {{6--r   c                 n   U R                   n[        U5      R                  U5      nU H  nUR                  U5      X5'   M     U R                  R
                  " U0 UD6R                  [        5      nSU;   a  UR                  SS 5      Ul	        SU;   a   [        UR                  SS5      5      Ul        U$ )NrM  r  r  F)r}  setintersectionpopr|  r  ri  r   r'  rM  r  r  )r|  r  r  r}  common_paramsprU  s          r   r  _convert2ma.__call__}"  s    ,,F009AAGJ  $$d5f5::;G=( 'L$ ?F&#GKKU$CDFr   )r   r}  r|  r  )
r   r   r   r   r   r}  r  r  r  r   r   r   r   rz  rz  C"  s"     G$

.8r   rz  r#   )rM  r  zarange : ndarrayzarange : MaskedArray)r  r~  r  r6   zclipped_array : ndarrayzclipped_array : MaskedArrayrI   zout : ndarrayzout : MaskedArrayrJ   )r~  r  rU   zout: MaskedArrayrW   zfromfunction : anyzfromfunction: MaskedArrayr_   ra   z'grid : one ndarray or tuple of ndarraysz/grid : one MaskedArray or tuple of MaskedArraysr   r   r   zsqueezed : ndarrayzsqueezed : MaskedArrayr   r   c                     [        X/U5      $ )a  Append values to the end of an array.

Parameters
----------
a : array_like
    Values are appended to a copy of this array.
b : array_like
    These values are appended to a copy of `a`.  It must be of the
    correct shape (the same shape as `a`, excluding `axis`).  If `axis`
    is not specified, `b` can be any shape and will be flattened
    before use.
axis : int, optional
    The axis along which `v` are appended.  If `axis` is not given,
    both `a` and `b` are flattened before use.

Returns
-------
append : MaskedArray
    A copy of `a` with `b` appended to `axis`.  Note that `append`
    does not occur in-place: a new array is allocated and filled.  If
    `axis` is None, the result is a flattened array.

See Also
--------
numpy.append : Equivalent function in the top-level NumPy module.

Examples
--------
>>> import numpy as np
>>> import numpy.ma as ma
>>> a = ma.masked_values([1, 2, 3], 2)
>>> b = ma.masked_values([[4, 5, 6], [7, 8, 9]], 7)
>>> ma.append(a, b)
masked_array(data=[1, --, 3, 4, 5, 6, --, 8, 9],
             mask=[False,  True, False, False, False, False,  True, False,
                   False],
       fill_value=999999)
)r:   )rS  r   r  s      r   r"   r"   "  s    N vt$$r   r  )T)FT)TT)h㈵>:0yE>TTr  r  r  r  r  )Nr  r  )FN)validT)r  T)Tr  r  (-  r   rt  r  r   rz  r   textwrapr   typingr   numpyr  numpy._core.umathr^  r  numpy._core.numerictypesnumerictypesr@  numpy._corer   rB  r   r   r   r   r	   r
   r   r   r5  r   r   r   numpy._core.numericr   numpy._utils._inspectr   r   numpy._utilsr   __all__r  r   r   r  r   r   r   r   r  r   r   r&  r  
datetime64timedelta64halfsingledouble
longdoublecsinglecdoubleclongdoublefloat_types_listr  r/  r  __annotations__r  
sctypeDictr  sctyper  scalar_dtyper%  int64infor   r   min_valmax_valrS  rA  rT  r:  r  infcomplexr7  r  r"  rD   r5  r   r   r>  rP  r   rV  r7   rN   rc  rX   get_datarO   rv  r  r  rx  r  r  r  r  r  r  r  r  rL   r;   r   r?   r(   r'   r   r@   r   r   r   rM   r   rR   r4   r.   rp   r   rl   rn   rm   r   r&   r$   r%   r*   r   r   r   r)   rK   r  r   rk   r\   rj   r[   ro   r   rq   r   rr   r1   r2   r3   r^   rH   r   rS   r   rT   r   r  r  rt   rY   get_maskrZ   rf   r  rs   ru   r  rv   rP   r5  r   rz   r{   r~   r   r   ry   r|   r   r   r   r}   r\  r   ru  r[  dedentra  r~  rQ   r  r  r   r  r   re   rh   rd   r]  rw   r   rx   rg   r  r   r  r   r    r   r!   r8   rB   rC   r=   rF   r]   r`   r   r   r   r   r   r   r   r   rV  r   r   r   r   r   r   rA   r   r   r,   r+   r-   r   r9   r:   rE   ri   r   r   r   r   r   r   r   r   r   rG   r   r5   r   r   r`  r-  rb   rc   r   r   rh  r>   r<   r   r   r0   r/   r  rv  rV   rz  r#   r6   rI   rJ   rU   rW   r_   ra   r   r   r   r   r   r"   )r[  s   0r   <module>r     s  ,       	   ! ! ) ) ( K K K < < 4 ; #"H 77	!	} 	8> 	"	i 		 	 #	
A&(mmE1&=N519s?#&(nnUA&>N519s?#

 GGRYY		2==JJ

BNN<  $tSy/ $tSy/ &&(F88F#LD xx!88a<	|RZZ	0	0xx88TXX	|R[[	1	1xx88TXX			c	!%HVHV% )( 
 
  )9"1)=>)=Aw<)=> ? 
  ;KBC;PQ;Paww01;PQ R
 
  *:2A*>?*>Q=*>? @ 
  ;KBC;PQ;Paww01;PQ R*(5<p<1<h1<h@3 l?D
B;|61h  Td 9v= ; ;2F F$K K*< < 6 6 - -GL GTP\ PhH| HX EII&!%//2	EII&EII&	u||	,

.UZZ(UZZ(UZZ(&u~~6 6he$UZZ( 0ekk*UZZ(	ryy	)#E$5$56 UZZ057EIIs*3/1UZZ+C02ekk3,S1	3EIIs&u-/	u||S3D#>
@	u||S3D#>
@
s 3C 8:
s 4\; OQ UYY'!%..1!%..!Q7
 S
9u{{+"5??3		 #E$4$45

 &u':':; ejj)
 
/$U%6%67
 !2!2Aq
9
@
@#E$4$45
$U%6%67$U%6%67#E$4$45
$U%6%67u{{+ 
"%,,0A0CQ	J&u'8'8'8':AqB'(:(:(9(;QC$U__%6%8!Q@	

,=,?AFuyy*;*=q!D@C3D9'x 3lBJ D Xv0f@6Ir61r +-++ xv96?666<6;6B&1R&1RBCJFR"R- -` ). $ __   __   oo  
 oo  + DC5p*Zk k\ Jc;' c; c;LwHEK EZ1&h n4[ n4b +, ,	 d$$$d!@ $$3vA AF DTBKK 	6 oo%%DTBKK 	6 oo%% DTBKK 6 oo%%'- '-T %v& &	D%zD1
i
 	X	6z"-(%
U]]G5G
H6
U]]D2D
E
i
 6
f
G	X	-(-(%%z"G%G:L\ 
X		X	KKd$I'+I %%--((V$&N:z0f-'`"'J&=R6r$?N/&d>B! ww"   ' ww R[[ EZ  8 Y)xIX5l 	$Nb. ));=# ));=)&8LvK88vjZ/2d/Pn bb =
>ABG GT 
4%0$	
 
4%0$+	 	4%0!		 !

  

 
(
 4%0!	 4%04?	 
4%0!	 !	
 4%0&	 	4%0!		 !
'%IP ?Q @Qs   =w5.*w:3w?$*x