/ lib / numpy / ma / core.pyc
core.pyc
   1  o

   2  [��c�F�
   3  @s�
dZddlZddlZddlZddlZddlZddlZddlmZddl	Z
   4  ddlmm
Z
ddlmmZddlmZddl	mZmZmZmZmZmZddl	mZddlmZddlmZm Z m!Z!m"Z"m#Z#dd	l	m$Z$dd
   5  l%m&Z&gd�Z'e
   6  jZ(e(d�Z)Gdd
�d
e*�Z+dd�Z,dd�Z-dd�Z.Gdd�de/�Z0Gdd�de0�Z1dddddddddd �	Z2d!D]Z3e
   7  �4d"e3�e2d#e3d$<e
   8  �5d"e3�e2d%e3d$<q�e
   9  j6e
  10  j7e
  11  j8e
  12  j9e
  13  j:e
  14  j;e
  15  j<gZ=ej>Z?e?�@d&d'�e=dd(�D��e?�@d)d'�e=d*d�D��ejAZBeB�@d+d'�e=dd(�D��eB�@d,d'�e=d*d�D��[=d-d.�ZCd/d0�ZDd1d2�ZEd3d4�ZFd5d6�ZGd7d8�ZHd9d:�ZId;d<�ZJd=d>�ZKd?d@�ZLdAdB�ZM�dLdCdD�ZNdEdF�ZO�dMdGdH�ZPePZQe)ddfdIdJ�ZRdKdL�ZSiZTiZUGdMdN�dN�ZVGdOdP�dP�ZWGdQdR�dR�ZXGdSdT�dT�ZYGdUdV�dV�ZZGdWdX�dX�Z[GdYdZ�dZe[�Z\Gd[d\�d\e[�Z]Gd]d^�d^e[�Z^e\e
j_�Z_e\e
j`�Z`e\e
ja�Zae\e
jb�Zbe\e
jc�Zce\e
jd�Zde\e
je�Zee\e
jf�Zfe\e
jg�Zge\e
jh�ZiZhe\e�Ze\e
jj�Zje\e
jk�Zke\e
jl�Zle\e
jm�Zme\e
  16  jn�Zoe\e
jp�Zpe\e
jqd_eZd_��Zqe\e
jrd`eYd_��Zre\e
jsd`eYd_��Zse\e
jtd`eYd_��Zte\e
jud_eWda��Zue\e
jvd_eVdbd`��Zve\e
jwd_eVdbd`��Zwe\e
jxd`eZd`��Zxe\e
jyd_eVdcdd��Zye]e
jz�Zze]e
j{�Z{e]e
j|dede�Z|e]e
j}d_d`�Z}e]e
j~�Z~de~_e]e
j�Zde_e]e
j��Z�de�_e]e
j��Z�de�_e]e
j��Z�de�_e]e
j��Z�de�_e]e
j��Z�e]e
j�dede�jZ�e]e
j��Z�e�jZ�e]e
j��Z�e]e
j��Z�e]e
j��Z�e]e
j��Z�e]e
j��Z�e^e
j�eX�dde�Z�e^e
j�eX�dde�Z�e^e
j�eX�dde�Z�e^e
j�eX�dde�Z�e^e
j�eX�dde�Z�e^e
j�eX�dde�Z�dfdg�Z�dhdi�Z�djdk�Z�dldm�Z�e�Z�dndo�Z�dpdq�Z�drds�Z�dtde(fdudv�Z��dLdwdx�Z�dydz�Z��dNd{d|�Z�d}d~�Z�e
  17  jfdd��Z��dMd�d��Z��dMd�d��Z��dMd�d��Z��dMd�d��Z��dMd�d��Z��dMd�d��Z��dMd�d��Z��dMd�d��Z��dMd�d��Z��dOd�d��Z��dPd�d��Z��dMd�d��Z�Gd�d��d��Z�e�d��Z�d�d��Z�e�e��d��e��d��e��d��e��d��d��Z�d�d��Z�d�d��Z��dMd�d��Z�Gd�d��d��Z�Gd�d��d�e�Z�d�d��Z�Gd�d��d�e��Z�d�d��Z�e�Z�e�Z�Gd�d��d�e��Z�e��Z�Z�e�Z�ddtde)dddtdddf
  18  d�d��Ze�je_d�d��Z�Gd�d��d�e[�Z�ddde
  19  jfd�d��Z�e�j�je�_ddde
  20  jfd�d��Z�e�j�je�_ddde
  21  jfd�d„Z�e�j�je�_Gd�dĄdăZ�e�dŃZ�e�dƃZ�Z�e�dǃZ�e�d�ddɍZ�e�dʃZ�e�d˃Z�e�d̃Z�e�d̓Z�e�d΃Z�e�dσZ�e�e
j�e�eH�Z�e�dЃZ�e�e
j�e�eG�Z�e�dуZ�e�d҃Z�e�d҃Z�e�dӃZ�e�dԃZ�e�dՃZ�e�dփZ�e�d׃Z�e�d؃Z�e�dكZ�e�dڃZ�e�dۃZ�e�d܃Z�dQd�d߄Z�dLd�d�Z�e�d�Z�e�d�Z�e
  22  jddddfd�d�Z�e�j�je�_�dRd�d�Z�d�d�Z�dSd�d�Z�dSd�d�Z�d�d��Z�d�d�Z�dTd�d�Z�d�d��Z�dLd�d��Z�dUd�d��Z�d�d��Z�d�d��Z�e
  23  j�je�_�d�d�Z�e
  24  j�je�_�dL�d�d�Z�e
  25  j�je�_eef�d�d�Z��dV�d�d�Z��dW�d�d	�ZnenZ��dL�d
  26  �d�Z��dX�d�d
�Z��d�d�Z�e-e
  27  j�j�d�e�_e�Z��d�d�Z�e-e
  28  j�j�d�e�_e�Z��d�d�Z��dY�d�d�Z��dZ�d�d��Z�dM�d�d��Z�d[�d�d��Z�d\�d�d ��Z�dL�d!�d"��Z�ed�d#f�d$�d%��Z�d&�d'��ZG�d(�d)��d)��Z�e�d*e�ddt�d+��d,�d-�d.��Z	�e�d/e�ddt�d+��d0�d1�d.��Z
  29  �e�d2e�ddt�d+��d3�d4�d.��Z�e�d5e�ddt�d+��d6�d7�d.��Z�e�d8�d6�d7�d9��Z
�e�d:�d6�d;�d9��Z�e�d<�d=�d>�d9��Z�e�d?e�ddt�d+��d6�d7�d.��Z�e�d@e�ddt�d+��dA�dB�d.��Z�e�dCe�ddt�d+��d6�d7�d.��Z�e�dD�d6�d7�d9��Z�e�dEe�ddt�d+��dF�dG�d.��Z�e�dHe�ddt�d+��d6�d7�d.��Z�e�dI�d6�d7�d9��Z�dL�dJ�dK��ZdS(]a�
  30  numpy.ma : a package to handle missing or invalid values.
  31  
  32  This package was initially written for numarray by Paul F. Dubois
  33  at Lawrence Livermore National Laboratory.
  34  In 2006, the package was completely rewritten by Pierre Gerard-Marchant
  35  (University of Georgia) to make the MaskedArray class a subclass of ndarray,
  36  and to improve support of structured arrays.
  37  
  38  
  39  Copyright 1999, 2000, 2001 Regents of the University of California.
  40  Released for unlimited redistribution.
  41  
  42  * Adapted for numpy_core 2005 by Travis Oliphant and (mainly) Paul Dubois.
  43  * Subclassing of the base `ndarray` 2006 by Pierre Gerard-Marchant
  44    (pgmdevlist_AT_gmail_DOT_com)
  45  * Improvements suggested by Reggie Dugard (reggie_AT_merfinllc_DOT_com)
  46  
  47  .. moduleauthor:: Pierre Gerard-Marchant
  48  
  49  �N)�reduce)�
  50  multiarray)�ndarray�amax�amin�iscomplexobj�bool_�_NoValue)�array)�angle)�
  51  getargspec�
formatargspec�long�unicode�bytes)�expand_dims)�normalize_axis_tuple)��MAError�	MaskError�MaskType�MaskedArray�abs�absolute�add�all�allclose�allequal�alltruerrr�anom�	anomalies�any�append�arange�arccos�arccosh�arcsin�arcsinh�arctan�arctan2�arctanh�argmax�argmin�argsort�aroundr
  52  53  asanyarray�asarray�bitwise_and�
  54  bitwise_or�bitwise_xorr�ceil�choose�clip�common_fill_value�compress�
  55  compressed�concatenate�	conjugate�convolve�copy�	correlate�cos�cosh�count�cumprod�cumsum�default_fill_value�diag�diagonal�diff�divide�empty�
  56  empty_like�equal�expr�fabs�filled�fix_invalid�flatten_mask�flatten_structured_array�floor�floor_divide�fmod�
  57  frombuffer�fromflex�fromfunction�getdata�getmask�getmaskarray�greater�
greater_equal�harden_mask�hypot�identity�ids�indices�inner�innerproduct�isMA�
isMaskedArray�is_mask�	is_masked�isarray�
  58  left_shift�less�
  59  less_equal�log�log10�log2�logical_and�logical_not�
  60  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�
  61  zeros_likec@seZdZdS)�MaskedArrayFutureWarningN)�__name__�
  62  __module__�__qualname__�r�r���C:\Users\Jacks.GUTTSPC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\numpy\ma\core.pyr�Tsr�cCs"|jdkrdStjdtdd�dS)a�
  63      Adjust the axis passed to argsort, warning if necessary
  64  
  65      Parameters
  66      ----------
  67      arr
  68          The array which argsort was called on
  69  
  70      np.ma.argsort has a long-term bug where the default of the axis argument
  71      is wrong (gh-8701), which now must be kept for backwards compatibility.
  72      Thankfully, this only makes a difference when arrays are 2- or more-
  73      dimensional, so we only need a warning then.
  74      ������z�In the future the default for argsort will be axis=-1, not the current None, to match its documentation and np.argsort. Explicitly pass -1 or None to silence this warning.���
  75  stacklevelN)r��warnings�warnr�)�arrr�r�r��_deprecate_argsort_axisWs
  76  �r�cCs\|durdS|dur|St�dt�|��}dt�|�}d�|dd�|g|dd��S)z9
  77      Adds a Notes section to an existing docstring.
  78  
  79      Nz\n\s*?Notes\n\s*?-----z
  80  
  81  Notes
  82  -----
  83  %s
  84  �r�)�re�split�inspect�cleandoc�join)Z
  85  initialdoc�noteZ	notesplitZnotedocr�r�r��doc_notess$r�cCs,z	tt|��}W|Styd}Y|Sw)z%
  86      Get the signature from obj
  87  
  88      r�)r
r�	TypeError)�obj�sigr�r�r��get_object_signature�s��r�c@�eZdZdZdS)rz1
  89      Class for masked array related errors.
  90  
  91      N�r�r�r��__doc__r�r�r�r�r��rc@r�)rz)
  92      Class for mask related errors.
  93  
  94      Nr�r�r�r�r�r�r�rTy@��x�Dg@��x�Di?B�?sN/As???zN/A)	�b�c�f�i�O�S�u�V�U)
�Y�M�W�D�h�m�s�ms�us�ns�ps�fs�as�NaTzM8[�]zm8[cCsg|]}|tjf�qSr���np�inf��.0�kr�r�r��
  95  <listcomp>��r��cCs"g|]
}|ttjtj�f�qSr���complexr�r�r�r�r�r�r���"�����cCsg|]}|tj
  96  f�qSr�r�r�r�r�r�r��r�cCs"g|]
}|ttj
  97  tj
  98  �f�qSr�rr�r�r�r�r��rcsd�jdurt��fdd��jD��}tj|�d�dS�jr.�j\}}t|��}t�||�S���S)zR
  99      Recursively produce a fill value for `dtype`, calling f on scalar dtypes
 100      Nc3s$�|]
}t�t�|���VqdS�N)r�r
 101  �_recursive_fill_value�r��name��dtyper�r�r��	<genexpr>�s
 102  ��
 103  �z(_recursive_fill_value.<locals>.<genexpr>�r	r�)�names�tupler�r
 104  �subdtyper�full)r	r��vals�subtyper�Zsubvalr�rr�r�s
 105  �
 106  
 107  rcCs,t|tj�r|St|d�r|jSt�|�jS)z4 Convert the argument for *_fill_value into a dtype r	)�
 108  isinstancer�r	�hasattrr.�r�r�r�r��
_get_dtype_of�s
 109  
 110  rcCsdd�}t|�}t||�S)aN
 111      Return the default fill value for the argument object.
 112  
 113      The default filling value depends on the datatype of the input
 114      array or the type of the input scalar:
 115  
 116         ========  ========
 117         datatype  default
 118         ========  ========
 119         bool      True
 120         int       999999
 121         float     1.e20
 122         complex   1.e20+0j
 123         object    '?'
 124         string    'N/A'
 125         ========  ========
 126  
 127      For structured types, a structured scalar is returned, with each field the
 128      default fill value for its type.
 129  
 130      For subarray types, the fill value is an array of the same size containing
 131      the default scalar fill value.
 132  
 133      Parameters
 134      ----------
 135      obj : ndarray, dtype or scalar
 136          The array data-type or scalar for which the default fill value
 137          is returned.
 138  
 139      Returns
 140      -------
 141      fill_value : scalar
 142          The default fill value.
 143  
 144      Examples
 145      --------
 146      >>> np.ma.default_fill_value(1)
 147      999999
 148      >>> np.ma.default_fill_value(np.array([1.1, 2., np.pi]))
 149      1e+20
 150      >>> np.ma.default_fill_value(np.dtype(complex))
 151      (1e+20+0j)
 152  
 153      cSs.|jdvrt�|jdd�d�St�|jd�S)N�Mmr�r�)�kind�default_filler�get�strrr�r�r��_scalar_fill_values
 154  z.default_fill_value.<locals>._scalar_fill_value�rr)r�rr	r�r�r�rC�s-
 155  rCcs ��fdd�}t|�}t||�S)Nc
 156  s<z�|WSty}ztd|�d��d��d�d}~ww)NzUnsuitable type z for calculating �.)�KeyErrorr�)r	�e��extremum�
extremum_namer�r�rs
 157  ����z0_extremum_fill_value.<locals>._scalar_fill_valuer)r�r!r"rr	r�r r��_extremum_fill_values
 158  r#cC�t|td�S)a`
 159      Return the maximum value that can be represented by the dtype of an object.
 160  
 161      This function is useful for calculating a fill value suitable for
 162      taking the minimum of an array with a given dtype.
 163  
 164      Parameters
 165      ----------
 166      obj : ndarray, dtype or scalar
 167          An object that can be queried for it's numeric type.
 168  
 169      Returns
 170      -------
 171      val : scalar
 172          The maximum representable value.
 173  
 174      Raises
 175      ------
 176      TypeError
 177          If `obj` isn't a suitable numeric type.
 178  
 179      See Also
 180      --------
 181      maximum_fill_value : The inverse function.
 182      set_fill_value : Set the filling value of a masked array.
 183      MaskedArray.fill_value : Return current fill value.
 184  
 185      Examples
 186      --------
 187      >>> import numpy.ma as ma
 188      >>> a = np.int8()
 189      >>> ma.minimum_fill_value(a)
 190      127
 191      >>> a = np.int32()
 192      >>> ma.minimum_fill_value(a)
 193      2147483647
 194  
 195      An array of numeric data can also be passed.
 196  
 197      >>> a = np.array([1, 2, 3], dtype=np.int8)
 198      >>> ma.minimum_fill_value(a)
 199      127
 200      >>> a = np.array([1, 2, 3], dtype=np.float32)
 201      >>> ma.minimum_fill_value(a)
 202      inf
 203  
 204      r�)r#�
 205  min_fillerrr�r�r�r�+�0r�cCr$)ad
 206      Return the minimum value that can be represented by the dtype of an object.
 207  
 208      This function is useful for calculating a fill value suitable for
 209      taking the maximum of an array with a given dtype.
 210  
 211      Parameters
 212      ----------
 213      obj : ndarray, dtype or scalar
 214          An object that can be queried for it's numeric type.
 215  
 216      Returns
 217      -------
 218      val : scalar
 219          The minimum representable value.
 220  
 221      Raises
 222      ------
 223      TypeError
 224          If `obj` isn't a suitable numeric type.
 225  
 226      See Also
 227      --------
 228      minimum_fill_value : The inverse function.
 229      set_fill_value : Set the filling value of a masked array.
 230      MaskedArray.fill_value : Return current fill value.
 231  
 232      Examples
 233      --------
 234      >>> import numpy.ma as ma
 235      >>> a = np.int8()
 236      >>> ma.maximum_fill_value(a)
 237      -128
 238      >>> a = np.int32()
 239      >>> ma.maximum_fill_value(a)
 240      -2147483648
 241  
 242      An array of numeric data can also be passed.
 243  
 244      >>> a = np.array([1, 2, 3], dtype=np.int8)
 245      >>> ma.maximum_fill_value(a)
 246      -128
 247      >>> a = np.array([1, 2, 3], dtype=np.float32)
 248      >>> ma.maximum_fill_value(a)
 249      -inf
 250  
 251      r�)r#�
 252  max_fillerrr�r�r�r�^r&r�cCs�t�|t|j��}g}t||j�D],\}}||}|jr!|jd}|jdur1|�tt||���q|�tj	||d��
 253  ��qt|�S)a�
 254      Create a fill value for a structured dtype.
 255  
 256      Parameters
 257      ----------
 258      fillvalue : scalar or array_like
 259          Scalar or array representing the fill value. If it is of shorter
 260          length than the number of fields in dt, it will be resized.
 261      dt : dtype
 262          The structured dtype for which to create the fill value.
 263  
 264      Returns
 265      -------
 266      val : tuple
 267          A tuple of values corresponding to the structured fill value.
 268  
 269      rNr)r�r��lenr�ziprr!r
�_recursive_set_fill_valuer
 270  �item)�	fillvalue�dtZoutput_value�fvalr�cdtyper�r�r�r*�s
 271  
 272  r*c
 273  Cst�|�}|durt|�}nw|jdurOt|ttjf�r=z
 274  tj|d|d�}Wn_ty<}zd}t|||f�|�d}~wwtj	|t
 275  d�}tjt||�|d�}n6t|t�ra|j
dvrad}t||��z
 276  tj|d|d�}Wnttfy�}zd}t|||f�|�d}~wwt�|�S)	a
 277      Private function validating the given `fill_value` for the given dtype.
 278  
 279      If fill_value is None, it is set to the default corresponding to the dtype.
 280  
 281      If fill_value is not None, its value is forced to the given dtype.
 282  
 283      The result is always a 0d array.
 284  
 285      NF�r<r	z"Unable to transform %s to dtype %srZOSVUz6Cannot set fill value of string with array of dtype %sz(Cannot convert fill_value %s to dtype %s)r�r	rCrrr�voidr
 286 287  ValueErrorr/�objectr*r�charr��
OverflowError)�
 288  fill_value�ndtyper�err_msgr�r�r��_check_fill_value�s6
 289  
 290  
 291  �����
 292  r9cCst|t�r
 293  |�|�dS)a�
 294      Set the filling value of a, if a is a masked array.
 295  
 296      This function changes the fill value of the masked array `a` in place.
 297      If `a` is not a masked array, the function returns silently, without
 298      doing anything.
 299  
 300      Parameters
 301      ----------
 302      a : array_like
 303          Input array.
 304      fill_value : dtype
 305          Filling value. A consistency test is performed to make sure
 306          the value is compatible with the dtype of `a`.
 307  
 308      Returns
 309      -------
 310      None
 311          Nothing returned by this function.
 312  
 313      See Also
 314      --------
 315      maximum_fill_value : Return the default fill value for a dtype.
 316      MaskedArray.fill_value : Return current fill value.
 317      MaskedArray.set_fill_value : Equivalent method.
 318  
 319      Examples
 320      --------
 321      >>> import numpy.ma as ma
 322      >>> a = np.arange(5)
 323      >>> a
 324      array([0, 1, 2, 3, 4])
 325      >>> a = ma.masked_where(a < 3, a)
 326      >>> a
 327      masked_array(data=[--, --, --, 3, 4],
 328                   mask=[ True,  True,  True, False, False],
 329             fill_value=999999)
 330      >>> ma.set_fill_value(a, -999)
 331      >>> a
 332      masked_array(data=[--, --, --, 3, 4],
 333                   mask=[ True,  True,  True, False, False],
 334             fill_value=-999)
 335  
 336      Nothing happens if `a` is not a masked array.
 337  
 338      >>> a = list(range(5))
 339      >>> a
 340      [0, 1, 2, 3, 4]
 341      >>> ma.set_fill_value(a, 100)
 342      >>> a
 343      [0, 1, 2, 3, 4]
 344      >>> a = np.arange(5)
 345      >>> a
 346      array([0, 1, 2, 3, 4])
 347      >>> ma.set_fill_value(a, 100)
 348      >>> a
 349      array([0, 1, 2, 3, 4])
 350  
 351      N)rrr���ar6r�r�r�r��s
 352  <
 353  r�cCs t|t�r
 354  |j}|St|�}|S)zr
 355      Return the filling value of a, if any.  Otherwise, returns the
 356      default filling value for that type.
 357  
 358      )rrr6rC)r;�resultr�r�r��get_fill_values
 359  
 360  �r=cCs t|�}t|�}||kr|SdS)a
 361      Return the common filling value of two masked arrays, if any.
 362  
 363      If ``a.fill_value == b.fill_value``, return the fill value,
 364      otherwise return None.
 365  
 366      Parameters
 367      ----------
 368      a, b : MaskedArray
 369          The masked arrays for which to compare fill values.
 370  
 371      Returns
 372      -------
 373      fill_value : scalar or None
 374          The common fill value, or None.
 375  
 376      Examples
 377      --------
 378      >>> x = np.ma.array([0, 1.], fill_value=3)
 379      >>> y = np.ma.array([0, 1.], fill_value=3)
 380      >>> np.ma.common_fill_value(x, y)
 381      3.0
 382  
 383      N)r=)r;r��t1�t2r�r�r�r6+s
 384  r6cCsBt|d�r
 385  |�|�St|t�r|St|t�rt�|d�St�|�S)a�
 386      Return input as an array with masked data replaced by a fill value.
 387  
 388      If `a` is not a `MaskedArray`, `a` itself is returned.
 389      If `a` is a `MaskedArray` and `fill_value` is None, `fill_value` is set to
 390      ``a.fill_value``.
 391  
 392      Parameters
 393      ----------
 394      a : MaskedArray or array_like
 395          An input object.
 396      fill_value : array_like, optional.
 397          Can be scalar or non-scalar. If non-scalar, the
 398          resulting filled array should be broadcastable
 399          over input array. Default is None.
 400  
 401      Returns
 402      -------
 403      a : ndarray
 404          The filled array.
 405  
 406      See Also
 407      --------
 408      compressed
 409  
 410      Examples
 411      --------
 412      >>> x = np.ma.array(np.arange(9).reshape(3, 3), mask=[[1, 0, 0],
 413      ...                                                   [1, 0, 0],
 414      ...                                                   [0, 0, 0]])
 415      >>> x.filled()
 416      array([[999999,      1,      2],
 417             [999999,      4,      5],
 418             [     6,      7,      8]])
 419      >>> x.filled(fill_value=333)
 420      array([[333,   1,   2],
 421             [333,   4,   5],
 422             [  6,   7,   8]])
 423      >>> x.filled(fill_value=np.arange(3))
 424      array([[0, 1, 2],
 425             [0, 4, 5],
 426             [6, 7, 8]])
 427  
 428      rMr�)rrMrr�dictr�r
 429  r:r�r�r�rMKs
 430  -
 431  
 432  
 433  
 434  rMcGs�t|�dkr|d}t|t�rt|�}n%t}n"dd�|D�}|d}t|t�s)t}|dd�D]	}t||�r8|}q/|jdkr@tS|S)z�
 435      Return the youngest subclass of MaskedArray from a list of (masked) arrays.
 436  
 437      In case of siblings, the first listed takes over.
 438  
 439      r�rcS�g|]}t|��qSr�)�type�r�r;r�r�r�r���z'get_masked_subclass.<locals>.<listcomp>N�MaskedConstant)r(rrrB�
 440  issubclassr�)�arraysr��rclsZarrcls�clsr�r�r��get_masked_subclass�s 
 441  
 442  
 443  
 444  �
 445  rJcCs@z|j}Wntytj|d|d�}Ynw|s|�t�S|S)aE
 446      Return the data of a masked array as an ndarray.
 447  
 448      Return the data of `a` (if any) as an ndarray if `a` is a ``MaskedArray``,
 449      else return `a` as a ndarray or subclass (depending on `subok`) if not.
 450  
 451      Parameters
 452      ----------
 453      a : array_like
 454          Input ``MaskedArray``, alternatively a ndarray or a subclass thereof.
 455      subok : bool
 456          Whether to force the output to be a `pure` ndarray (False) or to
 457          return a subclass of ndarray if appropriate (True, default).
 458  
 459      See Also
 460      --------
 461      getmask : Return the mask of a masked array, or nomask.
 462      getmaskarray : Return the mask of a masked array, or full array of False.
 463  
 464      Examples
 465      --------
 466      >>> import numpy.ma as ma
 467      >>> a = ma.masked_equal([[1,2],[3,4]], 2)
 468      >>> a
 469      masked_array(
 470        data=[[1, --],
 471              [3, 4]],
 472        mask=[[False,  True],
 473              [False, False]],
 474        fill_value=2)
 475      >>> ma.getdata(a)
 476      array([[1, 2],
 477             [3, 4]])
 478  
 479      Equivalently use the ``MaskedArray`` `data` attribute.
 480  
 481      >>> a.data
 482      array([[1, 2],
 483             [3, 4]])
 484  
 485      F�r<�subok)�_data�AttributeErrorr�r
 486  �viewr)r;rL�datar�r�r�rW�s*
 487  �
 488  rWcCsXt|||dd�}t�t�|j��}|��s|S|j|O_|dur%|j}||j|<|S)aQ
 489      Return input with invalid data masked and replaced by a fill value.
 490  
 491      Invalid data means values of `nan`, `inf`, etc.
 492  
 493      Parameters
 494      ----------
 495      a : array_like
 496          Input array, a (subclass of) ndarray.
 497      mask : sequence, optional
 498          Mask. Must be convertible to an array of booleans with the same
 499          shape as `data`. True indicates a masked (i.e. invalid) data.
 500      copy : bool, optional
 501          Whether to use a copy of `a` (True) or to fix `a` in place (False).
 502          Default is True.
 503      fill_value : scalar, optional
 504          Value used for fixing invalid data. Default is None, in which case
 505          the ``a.fill_value`` is used.
 506  
 507      Returns
 508      -------
 509      b : MaskedArray
 510          The input array with invalid entries fixed.
 511  
 512      Notes
 513      -----
 514      A copy is performed by default.
 515  
 516      Examples
 517      --------
 518      >>> x = np.ma.array([1., -1, np.nan, np.inf], mask=[1] + [0]*3)
 519      >>> x
 520      masked_array(data=[--, -1.0, nan, inf],
 521                   mask=[ True, False, False, False],
 522             fill_value=1e+20)
 523      >>> np.ma.fix_invalid(x)
 524      masked_array(data=[--, -1.0, --, --],
 525                   mask=[ True, False,  True,  True],
 526             fill_value=1e+20)
 527  
 528      >>> fixed = np.ma.fix_invalid(x)
 529      >>> fixed.data
 530      array([ 1.e+00, -1.e+00,  1.e+20,  1.e+20])
 531      >>> x.data
 532      array([ 1., -1., nan, inf])
 533  
 534      T)r<�maskrLN)rwr�ro�isfiniterMr �_maskr6)r;rQr<r6�invalidr�r�r�rN�s0
 535  rNcCs,t|t�pt|t�o|ot�dd�|D��S)Ncss�|]}t|t�VqdSr)rr)r�r�r�r�r�r
 536  s�z/is_string_or_list_of_strings.<locals>.<genexpr>)rr�list�builtinsr)�valr�r�r��is_string_or_list_of_stringss
 537  �rXc@� eZdZdZdd�Zdd�ZdS)�_DomainCheckIntervalz~
 538      Define a valid interval, so that :
 539  
 540      ``domain_check_interval(a,b)(x) == True`` where
 541      ``x < a`` or ``x > b``.
 542  
 543      cCs"||kr	||}}||_||_dS)z9domain_check_interval(a,b)(x) = true where x < a or y > bN)r;r���selfr;r�r�r�r��__init__&s
 544  
 545  z_DomainCheckInterval.__init__cCsPtjdd��t�t�||j�t�||j��Wd�S1s!wYdS)�Execute the call behavior.�ignore�rTN)r��errstate�umathrprZr�rir;�r\�xr�r�r��__call__-s
 546  �$�z_DomainCheckInterval.__call__N�r�r�r�r�r]rer�r�r�r�rZsrZc@rY)�
 547  _DomainTanz
 548      Define a valid interval for the `tan` function, so that:
 549  
 550      ``domain_tan(eps) = True`` where ``abs(cos(x)) < eps``
 551  
 552      cC�
 553  ||_dS)z/domain_tan(eps) = true where abs(cos(x)) < eps)N)�eps)r\rir�r�r�r]>�
 554  z_DomainTan.__init__cCsJtjdd��t�t�t�|��|j�Wd�S1swYdS��Executes the call behavior.r_r`N)r�rarbrirr>rircr�r�r�reBs$�z_DomainTan.__call__Nrfr�r�r�r�rg6srgc@s"eZdZdZddd�Zdd�ZdS)�_DomainSafeDividez-
 555      Define a domain for safe division.
 556  
 557      NcCs
 558  ||_dSr)�	tolerance)r\rnr�r�r�r]N�
 559  z_DomainSafeDivide.__init__cCsx|jdurt�t�j|_t�|�t�|�}}tjdd��t�|�|jt�|�kWd�S1s5wYdS)Nr_r`)	rnr��finfo�float�tinyr/rarbrr[r�r�r�reQs
 560  $�z_DomainSafeDivide.__call__rrfr�r�r�r�rmHs
 561  rmc@rY)�_DomainGreaterz4
 562      DomainGreater(v)(x) is True where x <= v.
 563  
 564      cCrh)z'DomainGreater(v)(x) = true where x <= vN��critical_value�r\rur�r�r�r]crjz_DomainGreater.__init__cC�>tjdd��t�||j�Wd�S1swYdSrk)r�rarbrjrurcr�r�r�reg�$�z_DomainGreater.__call__Nrfr�r�r�r�rs]�rsc@rY)�_DomainGreaterEqualz8
 565      DomainGreaterEqual(v)(x) is True where x < v.
 566  
 567      cCrh)z+DomainGreaterEqual(v)(x) = true where x < vNrtrvr�r�r�r]srjz_DomainGreaterEqual.__init__cCrwrk)r�rarbrirurcr�r�r�rewrxz_DomainGreaterEqual.__call__Nrfr�r�r�r�rzmryrzc@seZdZdd�Zdd�ZdS)�_MaskedUFunccCs||_|j|_|j|_dSr)r�r�r�)r\�ufuncr�r�r�r]~sz_MaskedUFunc.__init__cCsd|j��S)NzMasked version of )r��r\r�r�r��__str__��z_MaskedUFunc.__str__N)r�r�r�r]r~r�r�r�r�r{}sr{cs*eZdZdZd�fdd�	Zdd�Z�ZS)	�_MaskedUnaryOperationa�
 568      Defines masked version of unary operations, where invalid values are
 569      pre-masked.
 570  
 571      Parameters
 572      ----------
 573      mufunc : callable
 574          The function for which to define a masked version. Made available
 575          as ``_MaskedUnaryOperation.f``.
 576      fill : scalar, optional
 577          Filling value, default is 0.
 578      domain : class instance
 579          Domain for the function. Should be one of the ``_Domain*``
 580          classes. Default is None.
 581  
 582      rNcs,t��|�||_||_|t|<|t|<dSr)�superr]�fill�domain�ufunc_domain�ufunc_fills)r\Zmufuncr�r���	__class__r�r�r]�s
 583  z_MaskedUnaryOperation.__init__cOs2t|�}|jdur@tjddd��|j|g|�Ri|��}Wd�n1s'wYt�|�}||�|�O}|t|�O}n'tjddd��|j|g|�Ri|��}Wd�n1s^wYt|�}|jsp|rnt	S|S|t
 584  ur�z
 585  tj|||d�Wn	ty�Ynw|�
t|��}||_|�|�|S)�-
 586          Execute the call behavior.
 587  
 588          Nr_�rGrT�r�)rWr�r�rar�rbrRrXr�rvr��copytor�rOrJrS�_update_from)r\r;�args�kwargs�dr<r��
masked_resultr�r�r�re�s4
 589  ���
 590  z_MaskedUnaryOperation.__call__�rN�r�r�r�r�r]re�
__classcell__r�r�r�r�r��sr�csFeZdZdZd�fdd�	Zdd�Zddd	�Zd
 591  d�Zddd
�Z�Z	S)�_MaskedBinaryOperationaC
 592      Define masked version of binary operations, where invalid
 593      values are pre-masked.
 594  
 595      Parameters
 596      ----------
 597      mbfunc : function
 598          The function for which to define a masked version. Made available
 599          as ``_MaskedBinaryOperation.f``.
 600      domain : class instance
 601          Default domain for the function. Should be one of the ``_Domain*``
 602          classes. Default is None.
 603      fillx : scalar, optional
 604          Filling value for the first argument, default is 0.
 605      filly : scalar, optional
 606          Filling value for the second argument, default is 0.
 607  
 608      rcs0t��|�||_||_dt|<||ft|<dS)zr
 609          abfunc(fillx, filly) must be defined.
 610  
 611          abfunc(x, filly) = x for all x to enable reduce.
 612  
 613          N)r�r]�fillx�fillyr�r�)r\Zmbfuncr�r�r�r�r�r]�s
 614  z_MaskedBinaryOperation.__init__cOsTt|�t|�}}t���tjddd�|j||g|�Ri|��}Wd�n1s,wYt|�t|�}}	|turN|	turEt}
 615  nt�t	|�|	�}
 616  n|	tur[t�|t	|��}
 617  nt�||	�}
 618  |j
 619  sj|
 620  rhtS|S|
 621  tur�|
 622  ��r�ztj
||d|
 623  d�Wn	ty�Ynw|�t||��}|
 624  |_t|t�r�|�|�|St|t�r�|�|�|S)r�r_r�N�unsafe��castingr�)rWr�ra�seterrr�rXr�rbrprYr�rvr r��	ExceptionrOrJrSrrr�)r\r;r�r�r��da�dbr<�ma�mbr�r�r�r�r�re�s>
 625  ��
 626  
 627  
 628 629  z_MaskedBinaryOperation.__call__Nc
 630  Cs�t|�}t|�}t||j�}|jdkr%|�d�}|tur%t|dd�}d|_|tur3|j�	||�}t}n|jj	|||d�}t
 631  j�	||�}|jsL|rJtS|S|�
|�}	||	_|	S)z:
 632          Reduce `target` along the given `axis`.
 633  
 634          r�r�T�r<�r�r)rJrXrMr�r�r�r�rrr�rrbrnrvrOrS)
 635  r\�target�axisr	�tclassr��t�tr�mrZ	masked_trr�r�r�r!s(
 636  
 637  
 638  z_MaskedBinaryOperation.reducec
 639  Cs�t|�t|�}}|j�||�}t|�}t|�}|tur#|tur#t}nt|�}t|�}tj�||�}|js9|r9t	S|turEt
 640  j|||d�|jsJ|S|�
t||��}	||	_|	S)zO
 641          Return the function applied to the outer product of a and b.
 642  
 643          r�)rWr�r�rXr�rYrbrpr�rvr�r�r�rOrJrS)
 644  r\r;r�r�r�r�r�r�r�Zmasked_dr�r�r�r�?s$
 645  z_MaskedBinaryOperation.outercCs0t|�}t||j�}|j�||�}|�|�}|S)zSAccumulate `target` along `axis` after filling with y fill
 646          value.
 647  
 648          )rJrMr�r��
 649  accumulaterO)r\r�r�r�r�r<r�r�r�r�r�Xs
 650  
 651  z!_MaskedBinaryOperation.accumulate�rrr��r)
 652  r�r�r�r�r]rerr�r�r�r�r�r�r�r��s
 653  /r�cs*eZdZdZd�fdd�	Zdd�Z�ZS)�_DomainedBinaryOperationaH
 654      Define binary operations that have a domain, like divide.
 655  
 656      They have no reduce, outer or accumulate.
 657  
 658      Parameters
 659      ----------
 660      mbfunc : function
 661          The function for which to define a masked version. Made available
 662          as ``_DomainedBinaryOperation.f``.
 663      domain : class instance
 664          Default domain for the function. Should be one of the ``_Domain*``
 665          classes.
 666      fillx : scalar, optional
 667          Filling value for the first argument, default is 0.
 668      filly : scalar, optional
 669          Filling value for the second argument, default is 0.
 670  
 671      rcs6t��|�||_||_||_|t|<||ft|<dS)zjabfunc(fillx, filly) must be defined.
 672             abfunc(x, filly) = x for all x to enable reduce.
 673          N)r�r]r�r�r�r�r�)r\Zdbfuncr�r�r�r�r�r�r]zsz!_DomainedBinaryOperation.__init__cOsLt|�t|�}}tjddd��|j||g|�Ri|��}Wd�n1s(wYt�|�}|t|�O}|t|�O}t�|jd�}	|	durQ||	||�O}|j	sZ|rXt
 674  S|Sztj|dd|d�t�||�}
 675  tj
|
 676  j|jdd�rx||
 677  7}Wn	ty�Ynw|�t||��}||_t|t�r�|�|�|St|t�r�|�|�|S)	r^r_r�Nrr�r��safe)r�)rWr�rar�rbrRrXr�rr�rvr�r��can_castr	r�rOrJrSrrr�)r\r;r�r�r�r�r�r<r�r�Z	masked_dar�r�r�r�re�s>���
 678  
 679  
 680 681  z!_DomainedBinaryOperation.__call__r�r�r�r�r�r�r�esr����?gz�����8g�g�������g�������?r�cCs�t}|jdur2g}|jD]}|j|}t|�dkr|d|f}|�|||d|�f�qt�|�}n|jrLt|j�}||jd|�|d<t�t	|��}n|}||krT|}|S)z=Private function allowing recursion in _replace_dtype_fields.Nr�r�r)
 682  �_replace_dtype_fields_recursiver�fieldsr(r!r�r	rrUr
)r	�primitive_dtype�_recurse�descrr�field�	new_dtyper�r�r�r�s"
 683  
 684  
 685  
 686  r�cCst�|�}t�|�}t||�S)z�
 687      Construct a dtype description list from a given dtype.
 688  
 689      Returns a new dtype object, with all fields and subtypes in the given type
 690      recursively replaced with `primitive_dtype`.
 691  
 692      Arguments are coerced to dtypes first.
 693      )r�r	r�)r	r�r�r�r��_replace_dtype_fields#s
 694  	
 695  
 696  r�cC�
 697  t|t�S)a�
 698      Construct a dtype description list from a given dtype.
 699  
 700      Returns a new dtype object, with the type of all fields in `ndtype` to a
 701      boolean type. Field names are not altered.
 702  
 703      Parameters
 704      ----------
 705      ndtype : dtype
 706          The dtype to convert.
 707  
 708      Returns
 709      -------
 710      result : dtype
 711          A dtype that looks like `ndtype`, the type of all fields is boolean.
 712  
 713      Examples
 714      --------
 715      >>> import numpy.ma as ma
 716      >>> dtype = np.dtype({'names':['foo', 'bar'],
 717      ...                   'formats':[np.float32, np.int64]})
 718      >>> dtype
 719      dtype([('foo', '<f4'), ('bar', '<i8')])
 720      >>> ma.make_mask_descr(dtype)
 721      dtype([('foo', '|b1'), ('bar', '|b1')])
 722      >>> ma.make_mask_descr(np.float32)
 723      dtype('bool')
 724  
 725      )r�r)r7r�r�r�rs1s
 726  rscCst|dt�S)a
 727      Return the mask of a masked array, or nomask.
 728  
 729      Return the mask of `a` as an ndarray if `a` is a `MaskedArray` and the
 730      mask is not `nomask`, else return `nomask`. To guarantee a full array
 731      of booleans of the same shape as a, use `getmaskarray`.
 732  
 733      Parameters
 734      ----------
 735      a : array_like
 736          Input `MaskedArray` for which the mask is required.
 737  
 738      See Also
 739      --------
 740      getdata : Return the data of a masked array as an ndarray.
 741      getmaskarray : Return the mask of a masked array, or full array of False.
 742  
 743      Examples
 744      --------
 745      >>> import numpy.ma as ma
 746      >>> a = ma.masked_equal([[1,2],[3,4]], 2)
 747      >>> a
 748      masked_array(
 749        data=[[1, --],
 750              [3, 4]],
 751        mask=[[False,  True],
 752              [False, False]],
 753        fill_value=2)
 754      >>> ma.getmask(a)
 755      array([[False,  True],
 756             [False, False]])
 757  
 758      Equivalently use the `MaskedArray` `mask` attribute.
 759  
 760      >>> a.mask
 761      array([[False,  True],
 762             [False, False]])
 763  
 764      Result when mask == `nomask`
 765  
 766      >>> b = ma.masked_array([[1,2],[3,4]])
 767      >>> b
 768      masked_array(
 769        data=[[1, 2],
 770              [3, 4]],
 771        mask=False,
 772        fill_value=999999)
 773      >>> ma.nomask
 774      False
 775      >>> ma.getmask(b) == ma.nomask
 776      True
 777      >>> b.mask == ma.nomask
 778      True
 779  
 780      rS)�getattrr�)r;r�r�r�rXRs8rXcCs,t|�}|turtt�|�t|dd��}|S)ae
 781      Return the mask of a masked array, or full boolean array of False.
 782  
 783      Return the mask of `arr` as an ndarray if `arr` is a `MaskedArray` and
 784      the mask is not `nomask`, else return a full boolean array of False of
 785      the same shape as `arr`.
 786  
 787      Parameters
 788      ----------
 789      arr : array_like
 790          Input `MaskedArray` for which the mask is required.
 791  
 792      See Also
 793      --------
 794      getmask : Return the mask of a masked array, or nomask.
 795      getdata : Return the data of a masked array as an ndarray.
 796  
 797      Examples
 798      --------
 799      >>> import numpy.ma as ma
 800      >>> a = ma.masked_equal([[1,2],[3,4]], 2)
 801      >>> a
 802      masked_array(
 803        data=[[1, --],
 804              [3, 4]],
 805        mask=[[False,  True],
 806              [False, False]],
 807        fill_value=2)
 808      >>> ma.getmaskarray(a)
 809      array([[False,  True],
 810             [False, False]])
 811  
 812      Result when mask == ``nomask``
 813  
 814      >>> b = ma.masked_array([[1,2],[3,4]])
 815      >>> b
 816      masked_array(
 817        data=[[1, 2],
 818              [3, 4]],
 819        mask=False,
 820        fill_value=999999)
 821      >>> ma.getmaskarray(b)
 822      array([[False, False],
 823             [False, False]])
 824  
 825      r	N)rXr�rtr�r�r�)r�rQr�r�r�rY�s/rYcCs$z|jjtuWStyYdSw)a)
 826      Return True if m is a valid, standard mask.
 827  
 828      This function does not check the contents of the input, only that the
 829      type is MaskType. In particular, this function returns False if the
 830      mask has a flexible dtype.
 831  
 832      Parameters
 833      ----------
 834      m : array_like
 835          Array to test.
 836  
 837      Returns
 838      -------
 839      result : bool
 840          True if `m.dtype.type` is MaskType, False otherwise.
 841  
 842      See Also
 843      --------
 844      ma.isMaskedArray : Test whether input is an instance of MaskedArray.
 845  
 846      Examples
 847      --------
 848      >>> import numpy.ma as ma
 849      >>> m = ma.masked_equal([0, 1, 0, 2, 3], 0)
 850      >>> m
 851      masked_array(data=[--, 1, --, 2, 3],
 852                   mask=[ True, False,  True, False, False],
 853             fill_value=0)
 854      >>> ma.is_mask(m)
 855      False
 856      >>> ma.is_mask(m.mask)
 857      True
 858  
 859      Input must be an ndarray (or have similar attributes)
 860      for it to be considered a valid mask.
 861  
 862      >>> m = [False, True, False]
 863      >>> ma.is_mask(m)
 864      False
 865      >>> m = np.array([False, True, False])
 866      >>> m
 867      array([False,  True, False])
 868      >>> ma.is_mask(m)
 869      True
 870  
 871      Arrays with complex dtypes don't return True.
 872  
 873      >>> dtype = np.dtype({'names':['monty', 'pithon'],
 874      ...                   'formats':[bool, bool]})
 875      >>> dtype
 876      dtype([('monty', '|b1'), ('pithon', '|b1')])
 877      >>> m = np.array([(True, False), (False, True), (True, False)],
 878      ...              dtype=dtype)
 879      >>> m
 880      array([( True, False), (False,  True), ( True, False)],
 881            dtype=[('monty', '?'), ('pithon', '?')])
 882      >>> ma.is_mask(m)
 883      False
 884  
 885      F)r	rBrrN�r�r�r�r�re�s
 886  >�recCs|jjdur|��stS|S)z-
 887      Shrink a mask to nomask if possible
 888      N)r	rr r�r�r�r�r��_shrink_mask	sr�FcCsh|turtSt|�}t|t�r |jjr |tjkr tj|j	|d�Stj
 889  t|d�||dd�}|r2t|�}|S)a�
 890      Create a boolean mask from an array.
 891  
 892      Return `m` as a boolean mask, creating a copy if necessary or requested.
 893      The function can accept any sequence that is convertible to integers,
 894      or ``nomask``.  Does not require that contents must be 0s and 1s, values
 895      of 0 are interpreted as False, everything else as True.
 896  
 897      Parameters
 898      ----------
 899      m : array_like
 900          Potential mask.
 901      copy : bool, optional
 902          Whether to return a copy of `m` (True) or `m` itself (False).
 903      shrink : bool, optional
 904          Whether to shrink `m` to ``nomask`` if all its values are False.
 905      dtype : dtype, optional
 906          Data-type of the output mask. By default, the output mask has a
 907          dtype of MaskType (bool). If the dtype is flexible, each field has
 908          a boolean dtype. This is ignored when `m` is ``nomask``, in which
 909          case ``nomask`` is always returned.
 910  
 911      Returns
 912      -------
 913      result : ndarray
 914          A boolean mask derived from `m`.
 915  
 916      Examples
 917      --------
 918      >>> import numpy.ma as ma
 919      >>> m = [True, False, True, True]
 920      >>> ma.make_mask(m)
 921      array([ True, False,  True,  True])
 922      >>> m = [1, 0, 1, 1]
 923      >>> ma.make_mask(m)
 924      array([ True, False,  True,  True])
 925      >>> m = [1, 0, 2, -3]
 926      >>> ma.make_mask(m)
 927      array([ True, False,  True,  True])
 928  
 929      Effect of the `shrink` parameter.
 930  
 931      >>> m = np.zeros(4)
 932      >>> m
 933      array([0., 0., 0., 0.])
 934      >>> ma.make_mask(m)
 935      False
 936      >>> ma.make_mask(m, shrink=False)
 937      array([False, False, False, False])
 938  
 939      Using a flexible `dtype`.
 940  
 941      >>> m = [1, 0, 1, 1]
 942      >>> n = [0, 1, 0, 0]
 943      >>> arr = []
 944      >>> for man, mouse in zip(m, n):
 945      ...     arr.append((man, mouse))
 946      >>> arr
 947      [(1, 0), (0, 1), (1, 0), (1, 0)]
 948      >>> dtype = np.dtype({'names':['man', 'mouse'],
 949      ...                   'formats':[np.int64, np.int64]})
 950      >>> arr = np.array(arr, dtype=dtype)
 951      >>> arr
 952      array([(1, 0), (0, 1), (1, 0), (1, 0)],
 953            dtype=[('man', '<i8'), ('mouse', '<i8')])
 954      >>> ma.make_mask(arr, dtype=dtype)
 955      array([(True, False), (False, True), (True, False), (True, False)],
 956            dtype=[('man', '|b1'), ('mouse', '|b1')])
 957  
 958      rT)r<r	rL)
r�rsrrr	r�r�rr�r�r
 959  rMr�)r�r<�shrinkr	r<r�r�r�rrsGrrcCs0|dur
tj|td�}|Stj|t|�d�}|S)a&
 960      Return a boolean mask of the given shape, filled with False.
 961  
 962      This function returns a boolean ndarray with all entries False, that can
 963      be used in common mask manipulations. If a complex dtype is specified, the
 964      type of each field is converted to a boolean type.
 965  
 966      Parameters
 967      ----------
 968      newshape : tuple
 969          A tuple indicating the shape of the mask.
 970      dtype : {None, dtype}, optional
 971          If None, use a MaskType instance. Otherwise, use a new datatype with
 972          the same fields as `dtype`, converted to boolean types.
 973  
 974      Returns
 975      -------
 976      result : ndarray
 977          An ndarray of appropriate shape and dtype, filled with False.
 978  
 979      See Also
 980      --------
 981      make_mask : Create a boolean mask from an array.
 982      make_mask_descr : Construct a dtype description list from a given dtype.
 983  
 984      Examples
 985      --------
 986      >>> import numpy.ma as ma
 987      >>> ma.make_mask_none((3,))
 988      array([False, False, False])
 989  
 990      Defining a more complex dtype.
 991  
 992      >>> dtype = np.dtype({'names':['foo', 'bar'],
 993      ...                   'formats':[np.float32, np.int64]})
 994      >>> dtype
 995      dtype([('foo', '<f4'), ('bar', '<i8')])
 996      >>> ma.make_mask_none((3,), dtype=dtype)
 997      array([(False, False), (False, False), (False, False)],
 998            dtype=[('foo', '|b1'), ('bar', '|b1')])
 999  
1000      Nr)r�r�rrs)�newshaper	r<r�r�r�rtls
1001  +�rtcCsV|jj}|D]"}||}|jjdurt|||||�qt�|||||�qdSr)r	r�_recursive_mask_orrbrp)�m1�m2�newmaskrrZcurrent1r�r�r�r��s�r�cCs�|tus|durt|dt�}t||||d�S|tus|dur,t|dt�}t||||d�S||ur6t|�r6|St|dd�t|dd�}}||krOtd||f��|jdurgt�t�	||�j
1002  |�}t|||�|Stt�
||�||d�S)a�
1003      Combine two masks with the ``logical_or`` operator.
1004  
1005      The result may be a view on `m1` or `m2` if the other is `nomask`
1006      (i.e. False).
1007  
1008      Parameters
1009      ----------
1010      m1, m2 : array_like
1011          Input masks.
1012      copy : bool, optional
1013          If copy is False and one of the inputs is `nomask`, return a view
1014          of the other input mask. Defaults to False.
1015      shrink : bool, optional
1016          Whether to shrink the output to `nomask` if all its values are
1017          False. Defaults to True.
1018  
1019      Returns
1020      -------
1021      mask : output mask
1022          The result masks values that are masked in either `m1` or `m2`.
1023  
1024      Raises
1025      ------
1026      ValueError
1027          If `m1` and `m2` have different flexible dtypes.
1028  
1029      Examples
1030      --------
1031      >>> m1 = np.ma.make_mask([0, 1, 1, 0])
1032      >>> m2 = np.ma.make_mask([1, 0, 0, 0])
1033      >>> np.ma.mask_or(m1, m2)
1034      array([ True,  True,  True, False])
1035  
1036      Fr	)r<r�r	NzIncompatible dtypes '%s'<>'%s'�r<r�)r�r�rrrrer2rr�rH�	broadcastr�r�rbrp)r�r�r<r�r	�dtype1�dtype2r�r�r�r�ru�s %
1037  rucsBdd�}�fdd��t�|�}�||��}tjdd�|D�td�S)a&
1038      Returns a completely flattened version of the mask, where nested fields
1039      are collapsed.
1040  
1041      Parameters
1042      ----------
1043      mask : array_like
1044          Input array, which will be interpreted as booleans.
1045  
1046      Returns
1047      -------
1048      flattened_mask : ndarray of bools
1049          The flattened input.
1050  
1051      Examples
1052      --------
1053      >>> mask = np.array([0, 0, 1])
1054      >>> np.ma.flatten_mask(mask)
1055      array([False, False,  True])
1056  
1057      >>> mask = np.array([(0, 0), (0, 1)], dtype=[('a', bool), ('b', bool)])
1058      >>> np.ma.flatten_mask(mask)
1059      array([False, False, False,  True])
1060  
1061      >>> mdtype = [('a', bool), ('b', [('ba', bool), ('bb', bool)])]
1062      >>> mask = np.array([(0, (0, 0)), (0, (0, 1))], dtype=mdtype)
1063      >>> np.ma.flatten_mask(mask)
1064      array([False, False, False, False, False,  True])
1065  
1066      cs&�jj}|dur�fdd�|D�S�S)zCFlatten the mask and returns a (maybe nested) sequence of booleans.Ncsg|]}t�|��qSr�)rOr�rQr�r�r�r�z3flatten_mask.<locals>._flatmask.<locals>.<listcomp>�r	r)rQ�mnamesr�r�r��	_flatmaskszflatten_mask.<locals>._flatmaskc3sN�z|D]}t|d�r�|�EdHq|VqWdSty&|VYdSw)z.Generates a flattened version of the sequence.�__iter__N)rr�)�sequence�element��
_flatsequencer�r�r�s�
1067  ��z#flatten_mask.<locals>._flatsequencecSsg|]}|�qSr�r��r��_r�r�r�r�sz flatten_mask.<locals>.<listcomp>r)r�r/r
1068  �bool)rQr�Z	flattenedr�r�r�rO�s
1069   
1070  rOcCs6|tjurind|i}|tur|jdd|i|��StS)z:Check whether there are masked values along the given axis�keepdimsr�Nr�)r�r	r�r)rQr�r�r�r�r�r��_check_mask_axissr�cCs�t|dd�}tj||dd�}|j|j}}|r#||kr#td||f��t|d�r3t||j�}t|�}nt	}|�
1071  |�}t|�|_|sRt|d�rRt
|�turR|j�
1072  �|_|S)a�
1073      Mask an array where a condition is met.
1074  
1075      Return `a` as an array masked where `condition` is True.
1076      Any masked values of `a` or `condition` are also masked in the output.
1077  
1078      Parameters
1079      ----------
1080      condition : array_like
1081          Masking condition.  When `condition` tests floating point values for
1082          equality, consider using ``masked_values`` instead.
1083      a : array_like
1084          Array to mask.
1085      copy : bool
1086          If True (default) make a copy of `a` in the result.  If False modify
1087          `a` in place and return a view.
1088  
1089      Returns
1090      -------
1091      result : MaskedArray
1092          The result of masking `a` where `condition` is True.
1093  
1094      See Also
1095      --------
1096      masked_values : Mask using floating point equality.
1097      masked_equal : Mask where equal to a given value.
1098      masked_not_equal : Mask where `not` equal to a given value.
1099      masked_less_equal : Mask where less than or equal to a given value.
1100      masked_greater_equal : Mask where greater than or equal to a given value.
1101      masked_less : Mask where less than a given value.
1102      masked_greater : Mask where greater than a given value.
1103      masked_inside : Mask inside a given interval.
1104      masked_outside : Mask outside a given interval.
1105      masked_invalid : Mask invalid values (NaNs or infs).
1106  
1107      Examples
1108      --------
1109      >>> import numpy.ma as ma
1110      >>> a = np.arange(4)
1111      >>> a
1112      array([0, 1, 2, 3])
1113      >>> ma.masked_where(a <= 2, a)
1114      masked_array(data=[--, --, --, 3],
1115                   mask=[ True,  True,  True, False],
1116             fill_value=999999)
1117  
1118      Mask array `b` conditional on `a`.
1119  
1120      >>> b = ['a', 'b', 'c', 'd']
1121      >>> ma.masked_where(a == 2, b)
1122      masked_array(data=['a', 'b', --, 'd'],
1123                   mask=[False, False,  True, False],
1124             fill_value='N/A',
1125                  dtype='<U1')
1126  
1127      Effect of the `copy` argument.
1128  
1129      >>> c = ma.masked_where(a <= 2, a)
1130      >>> c
1131      masked_array(data=[--, --, --, 3],
1132                   mask=[ True,  True,  True, False],
1133             fill_value=999999)
1134      >>> c[0] = 99
1135      >>> c
1136      masked_array(data=[99, --, --, 3],
1137                   mask=[False,  True,  True, False],
1138             fill_value=999999)
1139      >>> a
1140      array([0, 1, 2, 3])
1141      >>> c = ma.masked_where(a <= 2, a, copy=False)
1142      >>> c[0] = 99
1143      >>> c
1144      masked_array(data=[99, --, --, 3],
1145                   mask=[False,  True,  True, False],
1146             fill_value=999999)
1147      >>> a
1148      array([99,  1,  2,  3])
1149  
1150      When `condition` or `a` contain masked values.
1151  
1152      >>> a = np.arange(4)
1153      >>> a = ma.masked_where(a == 2, a)
1154      >>> a
1155      masked_array(data=[0, 1, --, 3],
1156                   mask=[False, False,  True, False],
1157             fill_value=999999)
1158      >>> b = np.arange(4)
1159      >>> b = ma.masked_where(b == 0, b)
1160      >>> b
1161      masked_array(data=[--, 1, 2, 3],
1162                   mask=[ True, False, False, False],
1163             fill_value=999999)
1164      >>> ma.masked_where(a == 3, b)
1165      masked_array(data=[--, 1, --, --],
1166                   mask=[ True, False,  True,  True],
1167             fill_value=999999)
1168  
1169      F�r�TrKzFInconsistent shape between the condition and the input (got %s and %s)rS)rrr�r
1170  r��
1171  IndexErrorrrurSrBrrOr�rQrXr�)�	conditionr;r<�condZcshape�ashaperIr<r�r�r�r�$s d�
1172  
1173  
1174  
1175  r�cC�tt||�||d�S)a�
1176      Mask an array where greater than a given value.
1177  
1178      This function is a shortcut to ``masked_where``, with
1179      `condition` = (x > value).
1180  
1181      See Also
1182      --------
1183      masked_where : Mask where a condition is met.
1184  
1185      Examples
1186      --------
1187      >>> import numpy.ma as ma
1188      >>> a = np.arange(4)
1189      >>> a
1190      array([0, 1, 2, 3])
1191      >>> ma.masked_greater(a, 2)
1192      masked_array(data=[0, 1, 2, --],
1193                   mask=[False, False, False,  True],
1194             fill_value=999999)
1195  
1196      r�)r�rZ�rd�valuer<r�r�r�ry��rycCr�)a
1197      Mask an array where greater than or equal to a given value.
1198  
1199      This function is a shortcut to ``masked_where``, with
1200      `condition` = (x >= value).
1201  
1202      See Also
1203      --------
1204      masked_where : Mask where a condition is met.
1205  
1206      Examples
1207      --------
1208      >>> import numpy.ma as ma
1209      >>> a = np.arange(4)
1210      >>> a
1211      array([0, 1, 2, 3])
1212      >>> ma.masked_greater_equal(a, 2)
1213      masked_array(data=[0, 1, --, --],
1214                   mask=[False, False,  True,  True],
1215             fill_value=999999)
1216  
1217      r�)r�r[r�r�r�r�rz�r�rzcCr�)a�
1218      Mask an array where less than a given value.
1219  
1220      This function is a shortcut to ``masked_where``, with
1221      `condition` = (x < value).
1222  
1223      See Also
1224      --------
1225      masked_where : Mask where a condition is met.
1226  
1227      Examples
1228      --------
1229      >>> import numpy.ma as ma
1230      >>> a = np.arange(4)
1231      >>> a
1232      array([0, 1, 2, 3])
1233      >>> ma.masked_less(a, 2)
1234      masked_array(data=[--, --, 2, 3],
1235                   mask=[ True,  True, False, False],
1236             fill_value=999999)
1237  
1238      r�)r�rir�r�r�r�r}�r�r}cCr�)a�
1239      Mask an array where less than or equal to a given value.
1240  
1241      This function is a shortcut to ``masked_where``, with
1242      `condition` = (x <= value).
1243  
1244      See Also
1245      --------
1246      masked_where : Mask where a condition is met.
1247  
1248      Examples
1249      --------
1250      >>> import numpy.ma as ma
1251      >>> a = np.arange(4)
1252      >>> a
1253      array([0, 1, 2, 3])
1254      >>> ma.masked_less_equal(a, 2)
1255      masked_array(data=[--, --, --, 3],
1256                   mask=[ True,  True,  True, False],
1257             fill_value=999999)
1258  
1259      r�)r�rjr�r�r�r�r~�r�r~cCr�)a�
1260      Mask an array where `not` equal to a given value.
1261  
1262      This function is a shortcut to ``masked_where``, with
1263      `condition` = (x != value).
1264  
1265      See Also
1266      --------
1267      masked_where : Mask where a condition is met.
1268  
1269      Examples
1270      --------
1271      >>> import numpy.ma as ma
1272      >>> a = np.arange(4)
1273      >>> a
1274      array([0, 1, 2, 3])
1275      >>> ma.masked_not_equal(a, 2)
1276      masked_array(data=[--, --, 2, --],
1277                   mask=[ True,  True, False,  True],
1278             fill_value=999999)
1279  
1280      r�)r�r�r�r�r�r�rr�rcCstt||�||d�}||_|S)a�
1281      Mask an array where equal to a given value.
1282  
1283      Return a MaskedArray, masked where the data in array `x` are
1284      equal to `value`. The fill_value of the returned MaskedArray
1285      is set to `value`.
1286  
1287      For floating point arrays, consider using ``masked_values(x, value)``.
1288  
1289      See Also
1290      --------
1291      masked_where : Mask where a condition is met.
1292      masked_values : Mask using floating point equality.
1293  
1294      Examples
1295      --------
1296      >>> import numpy.ma as ma
1297      >>> a = np.arange(4)
1298      >>> a
1299      array([0, 1, 2, 3])
1300      >>> ma.masked_equal(a, 2)
1301      masked_array(data=[0, 1, --, 3],
1302                   mask=[False, False,  True, False],
1303             fill_value=2)
1304  
1305      r�)r�rJr6)rdr�r<�outputr�r�r�rx srxcCs8||kr	||}}t|�}||k||k@}t|||d�S)a�
1306      Mask an array inside a given interval.
1307  
1308      Shortcut to ``masked_where``, where `condition` is True for `x` inside
1309      the interval [v1,v2] (v1 <= x <= v2).  The boundaries `v1` and `v2`
1310      can be given in either order.
1311  
1312      See Also
1313      --------
1314      masked_where : Mask where a condition is met.
1315  
1316      Notes
1317      -----
1318      The array `x` is prefilled with its filling value.
1319  
1320      Examples
1321      --------
1322      >>> import numpy.ma as ma
1323      >>> x = [0.31, 1.2, 0.01, 0.2, -0.4, -1.1]
1324      >>> ma.masked_inside(x, -0.3, 0.3)
1325      masked_array(data=[0.31, 1.2, --, --, -0.4, -1.1],
1326                   mask=[False, False,  True,  True, False, False],
1327             fill_value=1e+20)
1328  
1329      The order of `v1` and `v2` doesn't matter.
1330  
1331      >>> ma.masked_inside(x, 0.3, -0.3)
1332      masked_array(data=[0.31, 1.2, --, --, -0.4, -1.1],
1333                   mask=[False, False,  True,  True, False, False],
1334             fill_value=1e+20)
1335  
1336      r��rMr��rd�v1�v2r<�xfr�r�r�r�r{@�
1337  !
1338  r{cCs8||kr	||}}t|�}||k||kB}t|||d�S)a�
1339      Mask an array outside a given interval.
1340  
1341      Shortcut to ``masked_where``, where `condition` is True for `x` outside
1342      the interval [v1,v2] (x < v1)|(x > v2).
1343      The boundaries `v1` and `v2` can be given in either order.
1344  
1345      See Also
1346      --------
1347      masked_where : Mask where a condition is met.
1348  
1349      Notes
1350      -----
1351      The array `x` is prefilled with its filling value.
1352  
1353      Examples
1354      --------
1355      >>> import numpy.ma as ma
1356      >>> x = [0.31, 1.2, 0.01, 0.2, -0.4, -1.1]
1357      >>> ma.masked_outside(x, -0.3, 0.3)
1358      masked_array(data=[--, --, 0.01, 0.2, --, --],
1359                   mask=[ True,  True, False, False,  True,  True],
1360             fill_value=1e+20)
1361  
1362      The order of `v1` and `v2` doesn't matter.
1363  
1364      >>> ma.masked_outside(x, 0.3, -0.3)
1365      masked_array(data=[--, --, 0.01, 0.2, --, --],
1366                   mask=[ True,  True, False, False,  True,  True],
1367             fill_value=1e+20)
1368  
1369      r�r�r�r�r�r�r�hr�r�cCsVt|�rt�|j|�}|j}nt�t�|�|�}t}t|t	||d��}t
1370  ||||d�S)a�
1371      Mask the array `x` where the data are exactly equal to value.
1372  
1373      This function is similar to `masked_values`, but only suitable
1374      for object arrays: for floating point, use `masked_values` instead.
1375  
1376      Parameters
1377      ----------
1378      x : array_like
1379          Array to mask
1380      value : object
1381          Comparison value
1382      copy : {True, False}, optional
1383          Whether to return a copy of `x`.
1384      shrink : {True, False}, optional
1385          Whether to collapse a mask full of False to nomask
1386  
1387      Returns
1388      -------
1389      result : MaskedArray
1390          The result of masking `x` where equal to `value`.
1391  
1392      See Also
1393      --------
1394      masked_where : Mask where a condition is met.
1395      masked_equal : Mask where equal to a given value (integers).
1396      masked_values : Mask using floating point equality.
1397  
1398      Examples
1399      --------
1400      >>> import numpy.ma as ma
1401      >>> food = np.array(['green_eggs', 'ham'], dtype=object)
1402      >>> # don't eat spoiled food
1403      >>> eat = ma.masked_object(food, 'green_eggs')
1404      >>> eat
1405      masked_array(data=[--, 'ham'],
1406                   mask=[ True, False],
1407             fill_value='green_eggs',
1408                  dtype=object)
1409      >>> # plain ol` ham is boring
1410      >>> fresh_food = np.array(['cheese', 'ham', 'pineapple'], dtype=object)
1411      >>> eat = ma.masked_object(fresh_food, 'green_eggs')
1412      >>> eat
1413      masked_array(data=['cheese', 'ham', 'pineapple'],
1414                   mask=False,
1415             fill_value='green_eggs',
1416                  dtype=object)
1417  
1418      Note that `mask` is set to ``nomask`` if possible.
1419  
1420      >>> eat
1421      masked_array(data=['cheese', 'ham', 'pineapple'],
1422                   mask=False,
1423             fill_value='green_eggs',
1424                  dtype=object)
1425  
1426      r��rQr<r6)rdrbrJrMrSr�r/r�rurrrw)rdr�r<r�r�rQr�r�r�r��s:r���h㈵��>�:�0�yE>c	CsZt||�}t�|jtj�rtj||||d�}nt�||�}t||||d�}|r+|�	�|S)a�
1427      Mask using floating point equality.
1428  
1429      Return a MaskedArray, masked where the data in array `x` are approximately
1430      equal to `value`, determined using `isclose`. The default tolerances for
1431      `masked_values` are the same as those for `isclose`.
1432  
1433      For integer types, exact equality is used, in the same way as
1434      `masked_equal`.
1435  
1436      The fill_value is set to `value` and the mask is set to ``nomask`` if
1437      possible.
1438  
1439      Parameters
1440      ----------
1441      x : array_like
1442          Array to mask.
1443      value : float
1444          Masking value.
1445      rtol, atol : float, optional
1446          Tolerance parameters passed on to `isclose`
1447      copy : bool, optional
1448          Whether to return a copy of `x`.
1449      shrink : bool, optional
1450          Whether to collapse a mask full of False to ``nomask``.
1451  
1452      Returns
1453      -------
1454      result : MaskedArray
1455          The result of masking `x` where approximately equal to `value`.
1456  
1457      See Also
1458      --------
1459      masked_where : Mask where a condition is met.
1460      masked_equal : Mask where equal to a given value (integers).
1461  
1462      Examples
1463      --------
1464      >>> import numpy.ma as ma
1465      >>> x = np.array([1, 1.1, 2, 1.1, 3])
1466      >>> ma.masked_values(x, 1.1)
1467      masked_array(data=[1.0, --, 2.0, --, 3.0],
1468                   mask=[False,  True, False,  True, False],
1469             fill_value=1.1)
1470  
1471      Note that `mask` is set to ``nomask`` if possible.
1472  
1473      >>> ma.masked_values(x, 2.1)
1474      masked_array(data=[1. , 1.1, 2. , 1.1, 3. ],
1475                   mask=False,
1476             fill_value=2.1)
1477  
1478      Unlike `masked_equal`, `masked_values` can perform approximate equalities. 
1479  
1480      >>> ma.masked_values(x, 2.1, atol=1e-1)
1481      masked_array(data=[1.0, 1.1, --, 1.1, 3.0],
1482                   mask=[False, False,  True, False, False],
1483             fill_value=2.1)
1484  
1485      )�atol�rtolr�)
1486  rMr��
1487  issubdtyper	�floating�iscloserbrJrw�shrink_mask)	rdr�r�r�r<r��xnewrQ�retr�r�r�r��s
1488  =r�cCsDtj|ddd�}tt�|�||d�}|jtur t|j|j�|_|S)a�
1489      Mask an array where invalid values occur (NaNs or infs).
1490  
1491      This function is a shortcut to ``masked_where``, with
1492      `condition` = ~(np.isfinite(a)). Any pre-existing mask is conserved.
1493      Only applies to arrays with a dtype where NaNs or infs make sense
1494      (i.e. floating point types), but accepts any array_like object.
1495  
1496      See Also
1497      --------
1498      masked_where : Mask where a condition is met.
1499  
1500      Examples
1501      --------
1502      >>> import numpy.ma as ma
1503      >>> a = np.arange(5, dtype=float)
1504      >>> a[2] = np.NaN
1505      >>> a[3] = np.PINF
1506      >>> a
1507      array([ 0.,  1., nan, inf,  4.])
1508      >>> ma.masked_invalid(a)
1509      masked_array(data=[0.0, 1.0, --, --, 4.0],
1510                   mask=[False, False,  True,  True, False],
1511             fill_value=1e+20)
1512  
1513      FTrKr�)	r�r
1514  r�rRrSr�rtr�r	)r;r<�resr�r�r�r|	s
1515  
1516  r|c@sFeZdZdZdd�Zdd�Zdd�Zdd	�Zddd�Zd
d�Z	e	Z
1517  dS)�_MaskedPrintOptionzN
1518      Handle the string used to represent missing data in a masked array.
1519  
1520      cCs||_d|_dS)z9
1521          Create the masked_print_option object.
1522  
1523          TN)�_display�_enabled)r\�displayr�r�r�r]J	s
1524  z_MaskedPrintOption.__init__cC�|jS)zA
1525          Display the string to print for masked values.
1526  
1527          �r�r}r�r�r�r�R	�z_MaskedPrintOption.displaycCrh)z=
1528          Set the string to print for masked values.
1529  
1530          Nr�)r\r�r�r�r��set_displayY	�
1531  z_MaskedPrintOption.set_displaycCr�)z;
1532          Is the use of the display value enabled?
1533  
1534          �r�r}r�r�r��enabled`	r�z_MaskedPrintOption.enabledr�cCrh)z7
1535          Set the enabling shrink to `shrink`.
1536  
1537          Nr�)r\r�r�r�r��enableg	r�z_MaskedPrintOption.enablecCs
1538  t|j�Sr)rr�r}r�r�r�r~n	roz_MaskedPrintOption.__str__Nr�)r�r�r�r�r]r�r�r�r�r~�__repr__r�r�r�r�r�D	s
1539  r�z--cCsN|jj}|dur|D]}||}||}t|||�q
1540  dStj|||d�dS)zg
1541      Puts printoptions in result where mask is True.
1542  
1543      Private function allowing for recursion
1544  
1545      Nr�)r	r�_recursive_printoptionr�r�)r<rQ�printoptrrZcurdataZcurmaskr�r�r�r�w	s�r�z�        masked_%(name)s(data =
1546           %(data)s,
1547          %(nlen)s        mask =
1548           %(mask)s,
1549          %(nlen)s  fill_value = %(fill)s)
1550          z�        masked_%(name)s(data =
1551           %(data)s,
1552          %(nlen)s        mask =
1553           %(mask)s,
1554          %(nlen)s  fill_value = %(fill)s,
1555          %(nlen)s       dtype = %(dtype)s)
1556          z�        masked_%(name)s(data = %(data)s,
1557          %(nlen)s        mask = %(mask)s,
1558          %(nlen)s  fill_value = %(fill)s)
1559          z�        masked_%(name)s(data = %(data)s,
1560          %(nlen)s        mask = %(mask)s,
1561          %(nlen)s  fill_value = %(fill)s,
1562          %(nlen)s       dtype = %(dtype)s)
1563          )Zlong_stdZlong_flxZ	short_stdZ	short_flxcCsX|jj}|D]#}||}|jjdurt|||||�qtj|||||d�qdS)z2
1564      Recursively fill `a` with `fill_value`.
1565  
1566      Nr�)r	r�_recursive_filledr�r�)r;rQr6rr�currentr�r�r�r��	s�r�cs��fdd��t�|�}|j}|��}t|t�r9t��fdd�|jD��}|�t�}t��fdd�t	|�D��|_
1567  nt��fdd�|D��}t|�dkr[t|j�}||d<t
�|��|_|S)	a:
1568      Flatten a structured array.
1569  
1570      The data type of the output is chosen such that it can represent all of the
1571      (nested) fields.
1572  
1573      Parameters
1574      ----------
1575      a : structured array
1576  
1577      Returns
1578      -------
1579      output : masked array or ndarray
1580          A flattened masked array if the input is a masked array, otherwise a
1581          standard ndarray.
1582  
1583      Examples
1584      --------
1585      >>> ndtype = [('a', int), ('b', float)]
1586      >>> a = np.array([(1, 1), (2, 2)], dtype=ndtype)
1587      >>> np.ma.flatten_structured_array(a)
1588      array([[1., 1.],
1589             [2., 2.]])
1590  
1591      c3s4�t|�D]}t|d�r�|�EdHq|VqdS)z;
1592          Flattens a compound of nested iterables.
1593  
1594          r�N)�iterr)�iterable�elm��flatten_sequencer�r�r�	s�
1595  �z2flatten_structured_array.<locals>.flatten_sequencec�g|]
1596  }t�|�����qSr��r
r+�r�r�rr�r�r��	�z,flatten_structured_array.<locals>.<listcomp>crr�rrrr�r�r��	s�crr�rrrr�r�r��	r	r�r)r�r.r�r�rrr
1597  rMrOrYrSr(rUr
)r;�inishape�outr�r�rr�rP�	s 
1598  
1599  
1600  �
1601  rPcs@��fdd�}tt�d�ptt�d�}|dur|j|_�|_|S)a
1602      Return a class method wrapper around a basic array method.
1603  
1604      Creates a class method which returns a masked array, where the new
1605      ``_data`` array is the output of the corresponding basic method called
1606      on the original ``_data``.
1607  
1608      If `onmask` is True, the new mask is the output of the method called
1609      on the initial mask. Otherwise, the new mask is just a reference
1610      to the initial mask.
1611  
1612      Parameters
1613      ----------
1614      funcname : str
1615          Name of the function to apply on data.
1616      onmask : bool
1617          Whether the mask must be processed also (True) or left
1618          alone (False). Default is True. Make available as `_onmask`
1619          attribute.
1620  
1621      Returns
1622      -------
1623      method : instancemethod
1624          Class method wrapper of the specified basic array method.
1625  
1626      csht|j��|i|��}|�t|��}|�|�|j}�s#|�|�|S|tur2t|��|i|��|_|Sr)r�rMrOrBr�rS�__setmask__r�)r\r��paramsr<rQ��funcname�onmaskr�r��wrapped_method
1627  s
1628  
1629  �z$_arraymethod.<locals>.wrapped_methodN)r�rr�r�r�)rrrZmethdocr�rr��_arraymethod�	src@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
1630  d�ZdS)
�MaskedIteratora�
1631      Flat iterator object to iterate over masked arrays.
1632  
1633      A `MaskedIterator` iterator is returned by ``x.flat`` for any masked array
1634      `x`. It allows iterating over the array as if it were a 1-D array,
1635      either in a for-loop or by calling its `next` method.
1636  
1637      Iteration is done in C-contiguous style, with the last index varying the
1638      fastest. The iterator can also be indexed using basic slicing or
1639      advanced indexing.
1640  
1641      See Also
1642      --------
1643      MaskedArray.flat : Return a flat iterator over an array.
1644      MaskedArray.flatten : Returns a flattened copy of an array.
1645  
1646      Notes
1647      -----
1648      `MaskedIterator` is not exported by the `ma` module. Instead of
1649      instantiating a `MaskedIterator` directly, use `MaskedArray.flat`.
1650  
1651      Examples
1652      --------
1653      >>> x = np.ma.array(arange(6).reshape(2, 3))
1654      >>> fl = x.flat
1655      >>> type(fl)
1656      <class 'numpy.ma.core.MaskedIterator'>
1657      >>> for item in fl:
1658      ...     print(item)
1659      ...
1660      0
1661      1
1662      2
1663      3
1664      4
1665      5
1666  
1667      Extracting more than a single element b indexing the `MaskedIterator`
1668      returns a masked array:
1669  
1670      >>> fl[2:4]
1671      masked_array(data = [2 3],
1672                   mask = False,
1673             fill_value = 999999)
1674  
1675      cCs2||_|jj|_|jturd|_dS|jj|_dSr)r�rM�flat�dataiterrSr��maskiter)r\r�r�r�r�r]M
1676  s
1677  
1678  
1679  
1680  zMaskedIterator.__init__cC�|Srr�r}r�r�r�r�V
1681  �zMaskedIterator.__iter__cCst|j�|��t|j��}|jdur8|j�|�}t|t�r%|j|_||_	|St|t
1682  j�r4t|||jj
d�S|r8tS|S)N�rQ�hardmask)r�__getitem__rOrBr�rrrr�rSr�r1r��	_hardmaskrv)r\�indxr<rSr�r�r�rY
1683  s
1684  
1685  �zMaskedIterator.__getitem__cCs.t|�|j|<|jdurt|�|j|<dSdSr)rWrrrY)r\�indexr�r�r�r��__setitem__h
1686  s
1687  �zMaskedIterator.__setitem__cCsHt|j�}|jdur"t|j�}t|tj�rt|||jjd�S|r"t	S|S)aT
1688          Return the next value, or raise StopIteration.
1689  
1690          Examples
1691          --------
1692          >>> x = np.ma.array([3, 2], mask=[0, 1])
1693          >>> fl = x.flat
1694          >>> next(fl)
1695          3
1696          >>> next(fl)
1697          masked
1698          >>> next(fl)
1699          Traceback (most recent call last):
1700            ...
1701          StopIteration
1702  
1703          Nr)
1704  �nextrrrr�r1r�r�rrv)r\r�r�r�r�r��__next__m
1705  s
1706  
1707  
1708  zMaskedIterator.__next__N)	r�r�r�r�r]r�rrr!r�r�r�r�r
1709  s/	rcsjeZdZdZdZeZdZeZ	dZ
1710  dZdedddddddddfd	d
1711  �Zdd�Z
d
d�Zd�dd�Zd�dd�Zdd�Zdd�Ze�fdd��Zej�fdd��Ze�fdd��Zej�fdd��Zd�dd�ZeZedd ��Zejd!d ��Zed"d#��Zejd$d#��Zd%d&�Zd'd(�Zed)d*��Zd+d,�Zed-d.��Zd/d0�Z ed1d2��Z!d3d4�Z"ee"d5�Z#ee"d5�Z$ed6d7��Z%e%jd8d7��Z%ed9d:��Z&e&jd�d;d:��Z&e&j'Z(e&j)Z*d�d<d=�Z+d>d?�Z,d�d@dA�Z-dBdC�Z.dDdE�Z/dFdG�Z0dHdI�Z1dJdK�Z2dLdM�Z3dNdO�Z4dPdQ�Z5dRdS�Z6dTdU�Z7dVdW�Z8dXdY�Z9dZd[�Z:d\d]�Z;d^d_�Z<d`da�Z=dbdc�Z>ddde�Z?dfdg�Z@dhdi�ZAdjdk�ZBdldm�ZCdndo�ZDdpdq�ZEdrds�ZFdtdu�ZGdvdw�ZHdxdy�ZIdzd{�ZJd|d}�ZKd~d�ZLd�d��ZMd�d��ZNed�d���ZOeOj'ZPed�d���ZQeQj'ZRdeSjTfd�d��ZUd�d�d��ZVd�d��ZWd�d�d��ZXd�d�d��ZYd�d��ZZd�d��Z[ddeSjTfd�d��Z\ddeSjTfd�d��Z]d�d��Z^d�fd�d��	Z_ej_je__d�d�d��Z`dddeSjTfd�d��Zad�d�d��ZbdddeSjTfd�d��ZcecZdd�d�d��ZedddeSjTf�fd�d��	Zfd�d�d��ZgddddeSjTf�fd�d��	ZheSjhjeh_ddddeSjTfd�d��Zid�d�d��ZjeSjTddddfd�d��Zkd�eSjTd��d�d��Zld�eSjTd��d�d��Zm		d�d�d��ZndddeSjTfd�d��ZodddeSjTfd�d„Zpd�d�dĄZq�fd�dƄZr�fd�dȄZsd�d�dʄZteud˃Zveud̃Zweud̓Zxeud΃ZyeudσZzeudЃZ{ed�d҄d5�Z|eudӃZ}d�d�dՄZ~d�d�dׄZd�d�dلZ�d�d�d݄Z�d�d߄Z�e�Z��fd�d�Z��fd�d�Z�d�d�Z�d�d�d�Z��Z�S)�raz
1712      An array class with possibly masked values.
1713  
1714      Masked values of True exclude the corresponding element from any
1715      computation.
1716  
1717      Construction::
1718  
1719        x = MaskedArray(data, mask=nomask, dtype=None, copy=False, subok=True,
1720                        ndmin=0, fill_value=None, keep_mask=True, hard_mask=None,
1721                        shrink=True, order=None)
1722  
1723      Parameters
1724      ----------
1725      data : array_like
1726          Input data.
1727      mask : sequence, optional
1728          Mask. Must be convertible to an array of booleans with the same
1729          shape as `data`. True indicates a masked (i.e. invalid) data.
1730      dtype : dtype, optional
1731          Data type of the output.
1732          If `dtype` is None, the type of the data argument (``data.dtype``)
1733          is used. If `dtype` is not None and different from ``data.dtype``,
1734          a copy is performed.
1735      copy : bool, optional
1736          Whether to copy the input data (True), or to use a reference instead.
1737          Default is False.
1738      subok : bool, optional
1739          Whether to return a subclass of `MaskedArray` if possible (True) or a
1740          plain `MaskedArray`. Default is True.
1741      ndmin : int, optional
1742          Minimum number of dimensions. Default is 0.
1743      fill_value : scalar, optional
1744          Value used to fill in the masked values when necessary.
1745          If None, a default based on the data-type is used.
1746      keep_mask : bool, optional
1747          Whether to combine `mask` with the mask of the input data, if any
1748          (True), or to use only `mask` for the output (False). Default is True.
1749      hard_mask : bool, optional
1750          Whether to use a hard mask or not. With a hard mask, masked values
1751          cannot be unmasked. Default is False.
1752      shrink : bool, optional
1753          Whether to force compression of an empty mask. Default is True.
1754      order : {'C', 'F', 'A'}, optional
1755          Specify the order of the array.  If order is 'C', then the array
1756          will be in C-contiguous order (last-index varies the fastest).
1757          If order is 'F', then the returned array will be in
1758          Fortran-contiguous order (first-index varies the fastest).
1759          If order is 'A' (default), then the returned array may be
1760          in any order (either C-, Fortran-contiguous, or even discontiguous),
1761          unless a copy is required, in which case it will be C-contiguous.
1762  
1763      Examples
1764      --------
1765  
1766      The ``mask`` can be initialized with an array of boolean values
1767      with the same shape as ``data``.
1768  
1769      >>> data = np.arange(6).reshape((2, 3))
1770      >>> np.ma.MaskedArray(data, mask=[[False, True, False],
1771      ...                               [False, False, True]])
1772      masked_array(
1773        data=[[0, --, 2],
1774              [3, 4, --]],
1775        mask=[[False,  True, False],
1776              [False, False,  True]],
1777        fill_value=999999)
1778  
1779      Alternatively, the ``mask`` can be initialized to homogeneous boolean
1780      array with the same shape as ``data`` by passing in a scalar
1781      boolean value:
1782  
1783      >>> np.ma.MaskedArray(data, mask=False)
1784      masked_array(
1785        data=[[0, 1, 2],
1786              [3, 4, 5]],
1787        mask=[[False, False, False],
1788              [False, False, False]],
1789        fill_value=999999)
1790  
1791      >>> np.ma.MaskedArray(data, mask=True)
1792      masked_array(
1793        data=[[--, --, --],
1794              [--, --, --]],
1795        mask=[[ True,  True,  True],
1796              [ True,  True,  True]],
1797        fill_value=999999,
1798        dtype=int64)
1799  
1800      .. note::
1801          The recommended practice for initializing ``mask`` with a scalar
1802          boolean value is to use ``True``/``False`` rather than
1803          ``np.True_``/``np.False_``. The reason is :attr:`nomask`
1804          is represented internally as ``np.False_``.
1805  
1806          >>> np.False_ is np.ma.nomask
1807          True
1808  
1809      �F�di�NTrcstj||||d|d��t|dt���}t|t�r |j�jkr d}t||�r5|r5t|t�s5t�	�t|���nt�	�|��t
1810  |d�rIt|t�sI|j�_t�j
��|tur�|se|
1811  r[t�_�ntj�j�d��_n�t|ttf�r�ztj�fdd�|D��d�}Wnty�t}Ynw�tkr�|��r�|�_d�_n�|�_|r��j���_t|�tur�|j|j_n�|dur��tkr�tj�j�d�}n3|durшtkr�tj�j�d�}n"z
1812  tj||�d	�}Wnty�tj�fd
1813  d�|D��d�}Ynw|j�jk�r'�j|j}
}|dk�rt�|�j�}n||
k�rt�|�j�}n
1814  d}t||
|f��d}�jtu�r5|�_|�_n*|�s@|�_|�_n�j
jd
u�rT�fdd����j|�nt�|�j��_d�_|d
u�rjt|dd
�}|d
u�rvt |�j
��_!|	d
u�r�t|dd��_"n|	�_"|�_#�S)z�
1815          Create a new masked array from scratch.
1816  
1817          Notes
1818          -----
1819          A masked array can also be created by taking a .view(MaskedArray).
1820  
1821          T)r	r<�orderrL�ndmin�
1822  _baseclassrSrcs g|]}ttj|�jd���qS)r)rYr�r.r	�r�r�)rMr�r�r�+s�z'MaskedArray.__new__.<locals>.<listcomp>Fr0c�g|]}t|gt����qSr��r
r(r'��mdtyper�r�r�H�r�z?Mask and data not compatible: data size is %i, mask size is %i.NcsD|jjD]}||||}}|jjdur�||�q||O}qdS)z'do a|=b on each field of a, recursivelyNr�)r;r�r�af�bf)�
_recursive_orr�r�r/`s
1823  �z*MaskedArray.__new__.<locals>._recursive_or�_fill_valuer)$r�r
1824  r�rBrrr�rErrOrrSrsr	r�r�r
rUr2rr �_sharedmaskr<rXr�r�r�r�r�rrrpr9r0rr&)rIrPrQr	r<rLr%r6�	keep_mask�	hard_maskr�r$r&�nd�nm�msgr�)rMr/r+r��__new__�
1825  s�
1826  �
1827  
1828  
1829  �
1830  ���
1831  �
1832  ��
1833  
1834  
1835  
1836  	
1837  
1838  
1839  zMaskedArray.__new__c	Cs�t|t�r
1840  t|�}nt}i}|�t|di��|�t|di��t|t�s.|�t|di��tt|dd�t|dd�t|dd�t|d	d�t|d
1841  |�||d�}|j�|�|j�|�dS)z9
1842          Copies some attributes of obj to self.
1843  
1844          �_optinfo�	_basedict�__dict__r0NrFr1�_isfieldr&)r0rr1r;r&r8r9)rrrB�updater�rr@r:)r\r�r&r8�_dictr�r�r�r�|s&
1845  
1846  
1847  
1848  
1849  
1850  
1851  �zMaskedArray._update_fromc	Cs<|�|�t|t�rV|jjdurt|�}nt|�}|turQ|jdd|jddkrQ|j|jkr5|j}nt	|j�}|j
1852  jrAd}n	|j
1853  jrHd}nd}|�
||�}n|��}nt}||_|jtur~z|j|j_Wntyst|_Ynttfy}Ynw|jdur�t|j|j�|_dS|jjdur�td|j�|_dSdS)z.
1854          Finalizes the masked array.
1855  
1856          NrPr�C�F�K)r�rrr	rrYrXr��__array_interface__rs�flags�c_contiguous�f_contiguous�astyperOrSr�r2r�rNr0r9)r\r�rSZ_mask_dtyper$r�r�r��__array_finalize__�sB
1857  
1858  
1859  	�
1860  
1861  
1862  
1863  �
1864  �zMaskedArray.__array_finalize__cCsP||ur|}n|�t|��}|�|�|dur�|j��|_|\}}}|d|j�}ttdd�|D��}t�	|d�}	|	dur�t
1865  jddd��t|	|�d�}
1866  Wd�n1sVwY|
1867  �
�r�zt|d}Wntytt|}Ynty|j}Ynwt
1868  j|||
1869  d�|tur�|
1870  }n||
1871  B}||ur�|jd	kr�|r�tS||_d
1872  |_|S)zr
1873          Special hook for ufuncs.
1874  
1875          Wraps the numpy array and sets the mask according to context.
1876  
1877          NcSrAr��rY)r��argr�r�r�r�rDz.MaskedArray.__array_wrap__.<locals>.<listcomp>r_r�Tr�r�r�F)rOrBr�rSr<�ninrrur�rr�rarMr r�r�rr6r�r�r�rvr1)r\r��contextr<�funcr��out_iZ
1878  input_argsr�r�r�r6r�r�r��__array_wrap__�s>
1879  
1880  �
1881  �zMaskedArray.__array_wrap__cCs�|dur|durt�|�}n8t�||�}n1|dur?zt|t�r(t�||�}d}nt�||�}Wnty>t�||�}Ynwt�|||�}t|�turR|j��|_t|dd�durm|durj|dure	|Sd|_|S||_	|S)a3
1882  
1883          Return a view of the MaskedArray data.
1884  
1885          Parameters
1886          ----------
1887          dtype : data-type or ndarray sub-class, optional
1888              Data-type descriptor of the returned view, e.g., float32 or int16.
1889              The default, None, results in the view having the same data-type
1890              as `a`. As with ``ndarray.view``, dtype can also be specified as
1891              an ndarray sub-class, which then specifies the type of the
1892              returned object (this is equivalent to setting the ``type``
1893              parameter).
1894          type : Python type, optional
1895              Type of the returned view, either ndarray or a subclass.  The
1896              default None results in type preservation.
1897          fill_value : scalar, optional
1898              The value to use for invalid entries (None by default).
1899              If None, then this argument is inferred from the passed `dtype`, or
1900              in its absence the original array, as discussed in the notes below.
1901  
1902          See Also
1903          --------
1904          numpy.ndarray.view : Equivalent method on ndarray object.
1905  
1906          Notes
1907          -----
1908  
1909          ``a.view()`` is used two different ways:
1910  
1911          ``a.view(some_dtype)`` or ``a.view(dtype=some_dtype)`` constructs a view
1912          of the array's memory with a different data-type.  This can cause a
1913          reinterpretation of the bytes of memory.
1914  
1915          ``a.view(ndarray_subclass)`` or ``a.view(type=ndarray_subclass)`` just
1916          returns an instance of `ndarray_subclass` that looks at the same array
1917          (same shape, dtype, etc.)  This does not cause a reinterpretation of the
1918          memory.
1919  
1920          If `fill_value` is not specified, but `dtype` is specified (and is not
1921          an ndarray sub-class), the `fill_value` of the MaskedArray will be
1922          reset. If neither `fill_value` nor `dtype` are specified (or if
1923          `dtype` is an ndarray sub-class), then the fill value is preserved.
1924          Finally, if `fill_value` is specified, but `dtype` is not, the fill
1925          value is set to the specified value.
1926  
1927          For ``a.view(some_dtype)``, if ``some_dtype`` has a different number of
1928          bytes per entry than the previous dtype (for example, converting a
1929          regular array to a structured array), then the behavior of the view
1930          cannot be predicted just from the superficial appearance of ``a`` (shown
1931          by ``print(a)``). It also depends on exactly how ``a`` is stored in
1932          memory. Therefore if ``a`` is C-ordered versus fortran-ordered, versus
1933          defined as a slice or transpose, etc., the view may give different
1934          results.
1935          Nr0)
1936  rrOrFr�rXr�rSr�r0r6)r\r	rBr6r�r�r�r�rO+s48
1937  ����zMaskedArray.viewcCs�|j|}|j}dd�}dd�}|tur||}||�}nt}||j|�}|dur1|t|�|�}|rbt|tj�rAt|||jd�S|j	j
1938  tjur\t|tj�r\|t
ur\|rZt|dd�S|S|r`t
S|S|�t
1939  |��}|�|�t|�r�|jdur�|j||_t|jtj�s�td	��|jjd
1940  kr�|j|jjd
1941  k��s�tjd|�d|jd
1942  �d
�dd�|jjd
1943  d�jd
1944  d�|_d|_|tur�t||j�|_d|_|S)zi
1945          x.__getitem__(y) <==> x[y]
1946  
1947          Return the item described by i, as a masked array.
1948  
1949          cSst|tj�Sr)rr�rr�r�r�r��
1950  _is_scalar��z+MaskedArray.__getitem__.<locals>._is_scalarcSsJt|tj�sdS|jjtjur|j|jurdSdSt|�jtjkr#dSdS)z�
1951              Return whether `elem` is a scalar result of indexing `arr`, or None
1952              if undecidable without promoting nomask to a full mask
1953              TFN)rr�rr	rB�object_r)r��elemr�r�r��_scalar_heuristic�s�z2MaskedArray.__getitem__.<locals>._scalar_heuristicNrTr�zInternal NumPy error.rz&Upon accessing multidimensional field zi, need to keep dimensionality of fill_value at 0. Discarding heterogeneous fill_value and setting all to r�r�r��r�)rPrSr�rYrr�r1r�rr	rBrPrrvrrOr�rXr0�RuntimeErrorr�rrr�r�r�r;r�r�r1)r\r�doutrSrNrR�moutZscalar_expectedr�r�r�r�sf
1954  
1955  
1956  �
1957  
1958  	
1959  �����
1960  zMaskedArray.__getitem__cCs�|turtd��|j}|j}t|t�r-|||<|tur%t|j|j	�|_}t
1961  |�||<dS|j	}|turZ|turAt|j|�}|_|jdurTtdgt
|j��||<dSd||<dSt|d|�}t
1962  |�}|jdurw|turwtdgt
|j��}|tur�|||<|tur�t|j|�}|_|||<dS|js�t|t�r�t|t�s�|||j<dS|||<|||<dSt|d�r�|j	tkr�|t�|�}|||<dS|jdur�d}t|��t|||dd�}	|j|}
1963  |
1964  jd	kr�tj|
1965  ||	d
1966  �n|	tur�|}
1967  |
1968  ||<|	||<dS)z�
1969          x.__setitem__(i, y) <==> x[i]=y
1970  
1971          Set item described by index. If value is masked, masks those
1972          locations.
1973  
1974          z Cannot alter the masked element.NTrMFr	z,Flexible 'hard' masks are not yet supported.r�r�r�)rvrrMrSrrr�rtr�r	rXrr
r(r�rrwrPrrrbro�NotImplementedErrorrur�r�r�)r\rr�rMrS�_dtype�dval�mvalr8ZmindxZdindxr�r�r�r
sl
1975  
1976  ��
1977  �
1978  ��
1979  �
1980  
1981  zMaskedArray.__setitem__c�t�jSr)r�r	r}r�r�r�r	I
�zMaskedArray.dtypec	sdttt|��j�||�|jtur0|j�t|�t	�|_z|j
1982  |j_
1983  WdSttfy/YdSwdSr)
r�rrBr	�__set__rSr�rOrsrr�rNr�)r\r	r�r�r�r	M
s
1984  ��cr\r)r�r�r}r�r�r�r�Y
r]zMaskedArray.shapecs6ttt|��j�||�t|�tur|j|j_dSdSr)r�rrBr�r^rXr�rS)r\r�r�r�r�r�]
s�csx|j}|j}|turd}|tur|turdSt|j|�}|_|jdur@|jr,||O}n�t|t	t
1985  tjtj
f�r<||d<nw||_ns|j�tj|dd�}|jsj|jjdkrdtjt|��gt����d�}n(|���}n"z
1986  tj||�d�}Wnty�tj�fd	d
1987  �|D��d�}Ynw|jr�|jD]}||||O<q�nt|t	t
1988  tjtj
f�r�||d<n||_|jr�|j|_dS)z 
1989          Set the mask.
1990  
1991          TN.Fr�r�rr0cr(r�r)r'r*r�r�r��
r,z+MaskedArray.__setmask__.<locals>.<listcomp>)r	rSrvr�rtr�rrr�intrqr�r�numberrr
1992  r�rr
r+r(rEr�)r\rQr<�idtypeZcurrent_mask�nr�r*r�re
sN
1993  
1994  
1995  �
1996  ��
1997  �
1998  zMaskedArray.__setmask__cC�
1999  |j��S)z Current mask. )rSrOr}r�r�r�rQ�
s
2000  zMaskedArray.maskcCs|�|�dSr)r)r\r�r�r�r�rQ�
�cCs.|j�t�}|jjdur|Stjt|�dd�S)a�
2001          Get or set the mask of the array if it has no named fields. For
2002          structured arrays, returns a ndarray of booleans where entries are
2003          ``True`` if **all** the fields are masked, ``False`` otherwise:
2004  
2005          >>> x = np.ma.array([(1, 1), (2, 2), (3, 3), (4, 4), (5, 5)],
2006          ...         mask=[(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)],
2007          ...        dtype=[('a', int), ('b', int)])
2008          >>> x.recordmask
2009          array([False, False,  True, False, False])
2010          Nr�rT)rSrOrr	rr�rrP)r\rSr�r�r��
2011  recordmask�
szMaskedArray.recordmaskcC�td��)Nz*Coming soon: setting the mask per records!�rX)r\rQr�r�r�re�
r]cC�
2012  d|_|S)a�
2013          Force the mask to hard, preventing unmasking by assignment.
2014  
2015          Whether the mask of a masked array is hard or soft is determined by
2016          its `~ma.MaskedArray.hardmask` property. `harden_mask` sets
2017          `~ma.MaskedArray.hardmask` to ``True`` (and returns the modified
2018          self).
2019  
2020          See Also
2021          --------
2022          ma.MaskedArray.hardmask
2023          ma.MaskedArray.soften_mask
2024  
2025          T�rr}r�r�r�r\�
�zMaskedArray.harden_maskcCrh)a�
2026          Force the mask to soft (default), allowing unmasking by assignment.
2027  
2028          Whether the mask of a masked array is hard or soft is determined by
2029          its `~ma.MaskedArray.hardmask` property. `soften_mask` sets
2030          `~ma.MaskedArray.hardmask` to ``False`` (and returns the modified
2031          self).
2032  
2033          See Also
2034          --------
2035          ma.MaskedArray.hardmask
2036          ma.MaskedArray.harden_mask
2037  
2038          Frir}r�r�r�r��
rjzMaskedArray.soften_maskcCr�)a�
2039          Specifies whether values can be unmasked through assignments.
2040  
2041          By default, assigning definite values to masked array entries will
2042          unmask them.  When `hardmask` is ``True``, the mask will not change
2043          through assignments.
2044  
2045          See Also
2046          --------
2047          ma.MaskedArray.harden_mask
2048          ma.MaskedArray.soften_mask
2049  
2050          Examples
2051          --------
2052          >>> x = np.arange(10)
2053          >>> m = np.ma.masked_array(x, x>5)
2054          >>> assert not m.hardmask
2055  
2056          Since `m` has a soft mask, assigning an element value unmasks that
2057          element:
2058  
2059          >>> m[8] = 42
2060          >>> m
2061          masked_array(data=[0, 1, 2, 3, 4, 5, --, --, 42, --],
2062                       mask=[False, False, False, False, False, False,
2063                             True, True, False, True],
2064                 fill_value=999999)
2065  
2066          After hardening, the mask is not affected by assignments:
2067  
2068          >>> hardened = np.ma.harden_mask(m)
2069          >>> assert m.hardmask and hardened is m
2070          >>> m[:] = 23
2071          >>> m
2072          masked_array(data=[23, 23, 23, 23, 23, 23, --, --, 23, --],
2073                       mask=[False, False, False, False, False, False,
2074                             True, True, False, True],
2075                 fill_value=999999)
2076  
2077          rir}r�r�r�r�
s*zMaskedArray.hardmaskcCs|jr|j��|_d|_|S)aY
2078          Copy the mask and set the `sharedmask` flag to ``False``.
2079  
2080          Whether the mask is shared between masked arrays can be seen from
2081          the `sharedmask` property. `unshare_mask` ensures the mask is not
2082          shared. A copy of the mask is only made if it was shared.
2083  
2084          See Also
2085          --------
2086          sharedmask
2087  
2088          F)r1rSr<r}r�r�r��unshare_mask!s
zMaskedArray.unshare_maskcCr�)z' Share status of the mask (read-only). )r1r}r�r�r��
2089  sharedmask3�zMaskedArray.sharedmaskcCst|j�|_|S)a
2090          Reduce a mask to nomask when possible.
2091  
2092          Parameters
2093          ----------
2094          None
2095  
2096          Returns
2097          -------
2098          None
2099  
2100          Examples
2101          --------
2102          >>> x = np.ma.array([[1,2 ], [3, 4]], mask=[0]*4)
2103          >>> x.mask
2104          array([[False, False],
2105                 [False, False]])
2106          >>> x.shrink_mask()
2107          masked_array(
2108            data=[[1, 2],
2109                  [3, 4]],
2110            mask=False,
2111            fill_value=999999)
2112          >>> x.mask
2113          False
2114  
2115          )r�rSr}r�r�r�r�8szMaskedArray.shrink_maskcCr�)z+ Class of the underlying data (read-only). )r&r}r�r�r��	baseclassWrmzMaskedArray.baseclasscCst�||j�S)a�
2116          Returns the underlying data, as a view of the masked array.
2117  
2118          If the underlying data is a subclass of :class:`numpy.ndarray`, it is
2119          returned as such.
2120  
2121          >>> x = np.ma.array(np.matrix([[1, 2], [3, 4]]), mask=[[0, 1], [1, 0]])
2122          >>> x.data
2123          matrix([[1, 2],
2124                  [3, 4]])
2125  
2126          The type of the data can be accessed through the :attr:`baseclass`
2127          attribute.
2128          )rrOr&r}r�r�r��	_get_data\szMaskedArray._get_data)�fgetcCst|�S)zF Return a flat iterator, or set a flattened version of self to value. )rr}r�r�r�rpszMaskedArray.flatcCs|��}||dd�<dSr)r�)r\r��yr�r�r�ruscCs4|jdurtd|j�|_t|jt�r|jdS|jS)a�
2129          The filling value of the masked array is a scalar. When setting, None
2130          will set to a default based on the data type.
2131  
2132          Examples
2133          --------
2134          >>> for dt in [np.int32, np.int64, np.float64, np.complex128]:
2135          ...     np.ma.array([0, 1], dtype=dt).get_fill_value()
2136          ...
2137          999999
2138          999999
2139          1e+20
2140          (1e+20+0j)
2141  
2142          >>> x = np.ma.array([0, 1.], fill_value=-np.inf)
2143          >>> x.fill_value
2144          -inf
2145          >>> x.fill_value = np.pi
2146          >>> x.fill_value
2147          3.1415926535897931 # may vary
2148  
2149          Reset to default:
2150  
2151          >>> x.fill_value = None
2152          >>> x.fill_value
2153          1e+20
2154  
2155          Nr�)r0r9r	rrr}r�r�r�r6zs
2156  
2157  
2158  zMaskedArray.fill_valuecCsJt||j�}|jdkstjdtdd�|j}|dur||_dS||d<dS)Nrz�Non-scalar arrays for the fill value are deprecated. Use arrays with scalar values instead. The filled function still supports any array as `fill_value`.rSr�r�)r9r	r�r�r��DeprecationWarningr0)r\r�r�r0r�r�r�r6�s
2159  �
2160  c	Cs|j}|tur
2161  |jS|dur|j}nt||j�}|tur!t�|�S|jj	dur6|j�
2162  d�}t||j|�|S|��s=|jS|j�
2163  d�}ztj
|||d�W|Sttfymt|td�}|�t�}t�|||f�}Y|Sty�|jjrx�|r�tj||jd�}Y|S|j}Y|Sw)a�
2164          Return a copy of self, with masked values filled with a given value.
2165          **However**, if there are no masked values to fill, self will be
2166          returned instead as an ndarray.
2167  
2168          Parameters
2169          ----------
2170          fill_value : array_like, optional
2171              The value to use for invalid entries. Can be scalar or non-scalar.
2172              If non-scalar, the resulting ndarray must be broadcastable over
2173              input array. Default is None, in which case, the `fill_value`
2174              attribute of the array is used instead.
2175  
2176          Returns
2177          -------
2178          filled_array : ndarray
2179              A copy of ``self`` with invalid entries replaced by *fill_value*
2180              (be it the function argument or the attribute of ``self``), or
2181              ``self`` itself as an ndarray if there are no invalid entries to
2182              be replaced.
2183  
2184          Notes
2185          -----
2186          The result is **not** a MaskedArray!
2187  
2188          Examples
2189          --------
2190          >>> x = np.ma.array([1,2,3,4,5], mask=[0,0,1,0,1], fill_value=-999)
2191          >>> x.filled()
2192          array([   1,    2, -999,    4, -999])
2193          >>> x.filled(fill_value=1000)
2194          array([   1,    2, 1000,    4, 1000])
2195          >>> type(x.filled())
2196          <class 'numpy.ndarray'>
2197  
2198          Subclassing is preserved. This means that if, e.g., the data part of
2199          the masked array is a recarray, `filled` returns a recarray:
2200  
2201          >>> x = np.array([(-1, 2), (-3, 4)], dtype='i8,i8').view(np.recarray)
2202          >>> m = np.ma.array(x, mask=[(True, False), (False, True)])
2203          >>> m.filled()
2204          rec.array([(999999,      2), (    -3, 999999)],
2205                    dtype=[('f0', '<i8'), ('f1', '<i8')])
2206          Nr@r�r)rSr�rMr6r9r	r�r�r.rr<r�r r�r�rN�narrayr3rEr4r�r�r
2207  )r\r6r�r<r�r�r�r�rM�s@-
2208  �
�
2209  	���zMaskedArray.filledcCs2t�|j�}|jtur|�t�t�|j���}|S)a�
2210          Return all the non-masked data as a 1-D array.
2211  
2212          Returns
2213          -------
2214          data : ndarray
2215              A new `ndarray` holding the non-masked data is returned.
2216  
2217          Notes
2218          -----
2219          The result is **not** a MaskedArray!
2220  
2221          Examples
2222          --------
2223          >>> x = np.ma.array(np.arange(5), mask=[0]*2 + [1]*3)
2224          >>> x.compressed()
2225          array([0, 1])
2226          >>> type(x.compressed())
2227          <class 'numpy.ndarray'>
2228  
2229          )rr�rMrSr�r7r�ro)r\rPr�r�r�r8
2230  s
2231  zMaskedArray.compressedcCsX|j|j}}t�|�}|j|||d��t|��}|�|�|tur*|j||d�|_|S)a+
2232          Return `a` where condition is ``True``.
2233  
2234          If condition is a `~ma.MaskedArray`, missing values are considered
2235          as ``False``.
2236  
2237          Parameters
2238          ----------
2239          condition : var
2240              Boolean 1-d array selecting which entries to return. If len(condition)
2241              is less than the size of a along the axis, then output is truncated
2242              to length of condition array.
2243          axis : {None, int}, optional
2244              Axis along which the operation must be performed.
2245          out : {None, ndarray}, optional
2246              Alternative output array in which to place the result. It must have
2247              the same shape as the expected output but the type will be cast if
2248              necessary.
2249  
2250          Returns
2251          -------
2252          result : MaskedArray
2253              A :class:`~ma.MaskedArray` object.
2254  
2255          Notes
2256          -----
2257          Please note the difference with :meth:`compressed` !
2258          The output of :meth:`compress` has a mask, the output of
2259          :meth:`compressed` does not.
2260  
2261          Examples
2262          --------
2263          >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
2264          >>> x
2265          masked_array(
2266            data=[[1, --, 3],
2267                  [--, 5, --],
2268                  [7, --, 9]],
2269            mask=[[False,  True, False],
2270                  [ True, False,  True],
2271                  [False,  True, False]],
2272            fill_value=999999)
2273          >>> x.compress([1, 0, 1])
2274          masked_array(data=[1, 3],
2275                       mask=[False, False],
2276                 fill_value=999999)
2277  
2278          >>> x.compress([1, 0, 1], axis=1)
2279          masked_array(
2280            data=[[1, 3],
2281                  [--, --],
2282                  [7, 9]],
2283            mask=[[False, False],
2284                  [ True,  True],
2285                  [False, False]],
2286            fill_value=999999)
2287  
2288          �r�rrT)	rMrSr�r/r7rOrBr�r�)r\r�r�rrMrS�_newr�r�r�r7%s<
2289  
2290  zMaskedArray.compressc	Cs�t��rt|j}|tur|j}|S|j}|jdkr|jn|j}t|j�D]=}|j	||kr`|d}t
2291  j|||f|d�}t
2292  j|d|df|d�}t
2293  j|||f|d�}t
2294  j|d|df|d�}q#t
|jd�}|�|�}t||t�|S|�|j�}|S)zq
2295          Replace masked values with masked_print_option, casting all innermost
2296          dtypes to object.
2297          r�rSrTrr�)r�r�rSr�rMr��_print_width�_print_width_1d�ranger�r�r�r9r�r	rEr�rMr6)	r\rQr�rPZprint_widthr��indr��rdtyper�r�r��_insert_masked_printms.���
2298  �z MaskedArray._insert_masked_printcCst|���Sr)rr{r}r�r�r�r~�rzMaskedArray.__str__c
s
2299  |jtjur	d}n|jj}tjj��dkrM|jdk}t|dt	|�t
2300  |�t
2301  |j�t
2302  |j�t
2303  |j
�d�}t|j
j�}d�|r?dnd|rDd	nd
2304  �}t||Sd|�d�}tjj�|j
�pft�|j�pf|jd
k}gd�}|rr|�d�t�dd�|jdd�D��}	d�|	r�i�|�|d
<|dd�D]}
2305  t��t	||d
�t	|
2306  ��}d|�|
2307  <q�d}n
�fdd�|D��|d}i�tj|��d�dddd��d<tj|jd�dddd��d<t|j��d <|r�tjj�|j
��d<d!���fd"d�|D��}||d#S)$z1
2308          Literal string representation.
2309  
2310          r
2311  �qr�� )r�nlenrPrQr�r	z{}_{}r�short�flxr��masked_�(r)rPrQr6r	css�|]}|dkVqdS)r�Nr�)r��dimr�r�r�r
2312  �s�z'MaskedArray.__repr__.<locals>.<genexpr>Nr�rSr�csi|]}|d��qS)r}r�r�)�
2313  min_indentr�r��
2314  <dictcomp>�sz(MaskedArray.__repr__.<locals>.<dictcomp>�
2315  z, rPzdata=�,)�	separator�prefix�suffixrQzmask=r6z,
2316  c3s&�|]}d��||�|�VqdS)z{}{}={}N)�formatr�)�indents�reprsr�r�r
2317  �s
2318  ��
2319  ��))r&r�rr��core�
2320  arrayprint�_get_legacy_print_moder�r@r(rrSr6r	r�rr��_legacy_print_templates�dtype_is_impliedrrQr�r!rVr�r��array2stringr{�repr�dtype_short_reprr�)
r\r�is_long�
2321  parametersZ
is_structured�keyr�Zdtype_needed�keysZ
2322  is_one_rowr�rbr<r�)r�r�r�r�r��sv
2323  
2324  �
2325  
2326  �
2327  ��
2328   
2329  
2330  �
2331  
2332  ��zMaskedArray.__repr__cCsDt|t|��r	dSt|dd�}|durt|dd�}|j|kS|duS)NF�__array_ufunc__�__array_priority__i����)rrBr�r�)r\�other�array_ufuncZother_priorityr�r�r��_delegate_binop�s
2333  zMaskedArray._delegate_binopc	Csdt|�}|j}t||dd�}t|�}|jjdurC|tjtjfvr"t	St
2334  �||�j}t
2335  j
||dd�}||_|�|�}	|t
2336  �d|j�k}n|j}	||	|�}
2337  t|
2338  t
2339  jtf�rY|rWtS|
2340  S|tur~|tjtjfvr~t
2341  �||||�|
2342  �}
2343  |j|
2344  jkr~t
2345  �
||
2346  j���}|
2347  �t|��}
2348  |
2349  �|�||
2350  _|
2351  jdur�z	t|
2352  jt
2353  j�}Wnttfy�tdt
2354  j�}Ynw||
2355  _|
2356  S)a�Compare self with other using operator.eq or operator.ne.
2357  
2358          When either of the elements is masked, the result is masked as well,
2359          but the underlying boolean data are still set, with self and other
2360          considered equal if both are masked, and unequal otherwise.
2361  
2362          For structured arrays, all fields are combined, with masked values
2363          ignored. The result is masked if all fields were masked, with self
2364          and other considered equal only if both were fully masked.
2365          Tr�N�rLr�) rXrQrurWr	r�operator�eq�ne�NotImplementedr�r�r��broadcast_torSrMr�rPrrr�rvr�r�r<rOrBr�r0r9r�r2)r\r��compare�omaskZsmaskrQ�odata�broadcast_shapeZ
2366  sbroadcast�sdata�checkr�r�r�r��_comparison�s>
2367  
2368  
2369  
2370  �zMaskedArray._comparisoncC�|�|tj�S)a�Check whether other equals self elementwise.
2371  
2372          When either of the elements is masked, the result is masked as well,
2373          but the underlying boolean data are still set, with self and other
2374          considered equal if both are masked, and unequal otherwise.
2375  
2376          For structured arrays, all fields are combined, with masked values
2377          ignored. The result is masked if all fields were masked, with self
2378          and other considered equal only if both were fully masked.
2379          )r�r�r��r\r�r�r�r��__eq__6�zMaskedArray.__eq__cCr�)a�Check whether other does not equal self elementwise.
2380  
2381          When either of the elements is masked, the result is masked as well,
2382          but the underlying boolean data are still set, with self and other
2383          considered equal if both are masked, and unequal otherwise.
2384  
2385          For structured arrays, all fields are combined, with masked values
2386          ignored. The result is masked if all fields were masked, with self
2387          and other considered equal only if both were fully masked.
2388          )r�r�r�r�r�r�r��__ne__Cr�zMaskedArray.__ne__cCr�r)r�r��ler�r�r�r��__le__QrOzMaskedArray.__le__cCr�r)r�r��ltr�r�r�r��__lt__TrOzMaskedArray.__lt__cCr�r)r�r��ger�r�r�r��__ge__WrOzMaskedArray.__ge__cCr�r)r�r��gtr�r�r�r��__gt__ZrOzMaskedArray.__gt__cC�|�|�rtSt||�S)zD
2389          Add self to other, and return a new masked array.
2390  
2391          )r�r�rr�r�r�r��__add__]�
2392  
2393  zMaskedArray.__add__cC�
2394  t||�S)zD
2395          Add other to self, and return a new masked array.
2396  
2397          )rr�r�r�r��__radd__f�
2398  zMaskedArray.__radd__cCr�)zK
2399          Subtract other from self, and return a new masked array.
2400  
2401          )r�r�r�r�r�r�r��__sub__or�zMaskedArray.__sub__cCr�)zK
2402          Subtract self from other, and return a new masked array.
2403  
2404          )r�r�r�r�r��__rsub__xr�zMaskedArray.__rsub__cCr�)z6Multiply self by other, and return a new masked array.)r�r�r�r�r�r�r��__mul__s
2405  
2406  zMaskedArray.__mul__cCr�)zI
2407          Multiply other by self, and return a new masked array.
2408  
2409          )r�r�r�r�r��__rmul__�r�zMaskedArray.__rmul__cCr��zI
2410          Divide other into self, and return a new masked array.
2411  
2412          )r�r�rGr�r�r�r��__div__�r�zMaskedArray.__div__cCr�r�)r�r�r�r�r�r�r��__truediv__�r�zMaskedArray.__truediv__cCr��zI
2413          Divide self into other, and return a new masked array.
2414  
2415          )r�r�r�r�r��__rtruediv__�r�zMaskedArray.__rtruediv__cCr�r�)r�r�rRr�r�r�r��__floordiv__�r�zMaskedArray.__floordiv__cCr�r�)rRr�r�r�r��
__rfloordiv__�r�zMaskedArray.__rfloordiv__cCr�)zQ
2416          Raise self to the power other, masking the potential NaNs/Infs
2417  
2418          )r�r�r�r�r�r�r��__pow__�r�zMaskedArray.__pow__cCr�)zQ
2419          Raise other to the power self, masking the potential NaNs/Infs
2420  
2421          )r�r�r�r�r��__rpow__�r�zMaskedArray.__rpow__cC�t|�}|jtur!|tur |��r t|j|j�|_|j|7_n|tur,|j|7_t|�}t�	|j|j�
2422  d�|�}|j�|�|S)z.
2423          Add other to self in-place.
2424  
2425          r)
rXrSr�r rtr�r	rWr�r�rBrM�__iadd__�r\r�r��
2426  other_datar�r�r�r��s
2427  �zMaskedArray.__iadd__cCr�)z5
2428          Subtract other from self in-place.
2429  
2430          r)
rXrSr�r rtr�r	rWr�r�rBrM�__isub__r�r�r�r�r���
2431  �zMaskedArray.__isub__cCr�)z3
2432          Multiply self by other in-place.
2433  
2434          r�)
rXrSr�r rtr�r	rWr�r�rBrM�__imul__r�r�r�r�r��r�zMaskedArray.__imul__cC�t|�}t��|j|�}t|�}t||�}|��r+ttj	\}}t�
2435  ||j�|�|�}|j
|O_
t�
2436  |j
|j�d�|�}|j�|�|S)z1
2437          Divide self by other in-place.
2438  
2439          r�)rWrmrerMrXrur r�r�rGr�r	rBrS�__idiv__�r\r�r�Zdom_mask�
2440  other_mask�new_maskr�r.r�r�r�r���
2441  �zMaskedArray.__idiv__cCr�)z7
2442          Floor divide self by other in-place.
2443  
2444          r�)rWrmrerMrXrur r�r�rRr�r	rBrS�
__ifloordiv__r�r�r�r�r�r�zMaskedArray.__ifloordiv__cCr�)z6
2445          True divide self by other in-place.
2446  
2447          r�)rWrmrerMrXrur r�r�r�r�r	rBrS�__itruediv__r�r�r�r�r�!r�zMaskedArray.__itruediv__cCs�t|�}t�|j|j�d�|�}t|�}tjddd��|j�	|�Wd�n1s,wYt�
2448  t�|j��}|��rX|jt
urK|j|O_n||_tj|j|j|d�t||�}t|j|�|_|S)z;
2449          Raise self to the power other, in place.
2450  
2451          r�r_r�Nr�)rWr�r�rSr	rBrXrarM�__ipow__rorRr r�r�r6ru)r\r�r�r�rTr�r�r�r�r�4s�
2452  
2453  zMaskedArray.__ipow__cCs8|jdkr	td��|jrtjddd�tjSt|���S)z$
2454          Convert to float.
2455  
2456          r��7Only length-1 arrays can be converted to Python scalarsz,Warning: converting a masked element to nan.rSr�)	r�r�rSr�r�r��nanrqr+r}r�r�r��	__float__Is
2457  zMaskedArray.__float__cCs,|jdkr	td��|jrtd��t|���S)z"
2458          Convert to int.
2459  
2460          r�r�z.Cannot convert masked element to a Python int.)r�r�rSrr_r+r}r�r�r��__int__Vs
2461  
2462  zMaskedArray.__int__cC�"|jj�t|��}|�|j�|S)a�
2463          The imaginary part of the masked array.
2464  
2465          This property is a view on the imaginary part of this `MaskedArray`.
2466  
2467          See Also
2468          --------
2469          real
2470  
2471          Examples
2472          --------
2473          >>> x = np.ma.array([1+1.j, -2j, 3.45+1.6j], mask=[False, True, False])
2474          >>> x.imag
2475          masked_array(data=[1.0, --, 1.6],
2476                       mask=[False,  True, False],
2477                 fill_value=1e+20)
2478  
2479          )rM�imagrOrBrrS�r\r<r�r�r�r�b�zMaskedArray.imagcCr�)a�
2480          The real part of the masked array.
2481  
2482          This property is a view on the real part of this `MaskedArray`.
2483  
2484          See Also
2485          --------
2486          imag
2487  
2488          Examples
2489          --------
2490          >>> x = np.ma.array([1+1.j, -2j, 3.45+1.6j], mask=[False, True, False])
2491          >>> x.real
2492          masked_array(data=[1.0, --, 3.45],
2493                       mask=[False,  True, False],
2494                 fill_value=1e+20)
2495  
2496          )rM�realrOrBrrSr�r�r�r�r�}r�zMaskedArray.realc	sT|tjurind|i}|j}t|jtj�r*|tur"tj|jtj	d�}|�
2497  t|j��}|tur�|jdkrA|dvr?tj||j
d��dS|durY|�dd�rVtj|jtj|j
d	�S|jSt||j
��d}�D]	}||j|9}qc|�dd�r�t|j�}�D]}d||<qzn�fd
2498  d�t|j�D�}tj||tjd�S|tur�dS|jd|tjd
�|��S)a
2499          Count the non-masked elements of the array along the given axis.
2500  
2501          Parameters
2502          ----------
2503          axis : None or int or tuple of ints, optional
2504              Axis or axes along which the count is performed.
2505              The default, None, performs the count over all
2506              the dimensions of the input array. `axis` may be negative, in
2507              which case it counts from the last to the first axis.
2508  
2509              .. versionadded:: 1.10.0
2510  
2511              If this is a tuple of ints, the count is performed on multiple
2512              axes, instead of a single axis or all the axes as before.
2513          keepdims : bool, optional
2514              If this is set to True, the axes which are reduced are left
2515              in the result as dimensions with size one. With this option,
2516              the result will broadcast correctly against the array.
2517  
2518          Returns
2519          -------
2520          result : ndarray or scalar
2521              An array with the same shape as the input array, with the specified
2522              axis removed. If the array is a 0-d array, or if `axis` is None, a
2523              scalar is returned.
2524  
2525          See Also
2526          --------
2527          ma.count_masked : Count masked elements in array or along a given axis.
2528  
2529          Examples
2530          --------
2531          >>> import numpy.ma as ma
2532          >>> a = ma.arange(6).reshape((2, 3))
2533          >>> a[1, :] = ma.masked
2534          >>> a
2535          masked_array(
2536            data=[[0, 1, 2],
2537                  [--, --, --]],
2538            mask=[[False, False, False],
2539                  [ True,  True,  True]],
2540            fill_value=999999)
2541          >>> a.count()
2542          3
2543  
2544          When the `axis` keyword is specified an array of appropriate size is
2545          returned.
2546  
2547          >>> a.count(axis=0)
2548          array([1, 1, 1])
2549          >>> a.count(axis=1)
2550          array([3, 0])
2551  
2552          r�rr��Nr)r�r�r�NF)r	r%csg|]
2553  \}}|�vr|�qSr�r�)r�rbr���axesr�r�r��s�z%MaskedArray.count.<locals>.<listcomp>r�r�r	)r�r	rSrrP�matrixr�r�r�rrOrB�	AxisErrorr�rr
2554  r��intprrU�	enumeraterrvr�)	r\r�r�r�r��items�axZout_dimsr;r�r�r�r@�s:8
2555  
2556  
2557  �zMaskedArray.countr>cCsVtj|j|d��t|��}|�|�|jtur&tj|j|d��|j	�|_|St|_|S)a
2558          Returns a 1D version of self, as a view.
2559  
2560          Parameters
2561          ----------
2562          order : {'C', 'F', 'A', 'K'}, optional
2563              The elements of `a` are read using this index order. 'C' means to
2564              index the elements in C-like order, with the last axis index
2565              changing fastest, back to the first axis index changing slowest.
2566              'F' means to index the elements in Fortran-like index order, with
2567              the first index changing fastest, and the last index changing
2568              slowest. Note that the 'C' and 'F' options take no account of the
2569              memory layout of the underlying array, and only refer to the order
2570              of axis indexing.  'A' means to read the elements in Fortran-like
2571              index order if `m` is Fortran *contiguous* in memory, C-like order
2572              otherwise.  'K' means to read the elements in the order they occur
2573              in memory, except for reversing the data when strides are negative.
2574              By default, 'C' index order is used.
2575  
2576          Returns
2577          -------
2578          MaskedArray
2579              Output view is of shape ``(self.size,)`` (or
2580              ``(np.ma.product(self.shape),)``).
2581  
2582          Examples
2583          --------
2584          >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
2585          >>> x
2586          masked_array(
2587            data=[[1, --, 3],
2588                  [--, 5, --],
2589                  [7, --, 9]],
2590            mask=[[False,  True, False],
2591                  [ True, False,  True],
2592                  [False,  True, False]],
2593            fill_value=999999)
2594          >>> x.ravel()
2595          masked_array(data=[1, --, 3, --, 5, --, 7, --, 9],
2596                       mask=[False,  True, False,  True, False,  True, False,  True,
2597                             False],
2598                 fill_value=999999)
2599  
2600          �r$)
2601  rr�rMrOrBr�rSr�r�r�)r\r$�rr�r�r�r��s-
2602  
2603  �zMaskedArray.ravelcOs^|j|�dd�d�|jj|i|���t|��}|�|�|j}|tur-|j|i|��|_|S)a�
2604          Give a new shape to the array without changing its data.
2605  
2606          Returns a masked array containing the same data, but with a new shape.
2607          The result is a view on the original array; if this is not possible, a
2608          ValueError is raised.
2609  
2610          Parameters
2611          ----------
2612          shape : int or tuple of ints
2613              The new shape should be compatible with the original shape. If an
2614              integer is supplied, then the result will be a 1-D array of that
2615              length.
2616          order : {'C', 'F'}, optional
2617              Determines whether the array data should be viewed as in C
2618              (row-major) or FORTRAN (column-major) order.
2619  
2620          Returns
2621          -------
2622          reshaped_array : array
2623              A new view on the array.
2624  
2625          See Also
2626          --------
2627          reshape : Equivalent function in the masked array module.
2628          numpy.ndarray.reshape : Equivalent method on ndarray object.
2629          numpy.reshape : Equivalent function in the NumPy module.
2630  
2631          Notes
2632          -----
2633          The reshaping operation cannot guarantee that a copy will not be made,
2634          to modify the shape in place, use ``a.shape = s``
2635  
2636          Examples
2637          --------
2638          >>> x = np.ma.array([[1,2],[3,4]], mask=[1,0,0,1])
2639          >>> x
2640          masked_array(
2641            data=[[--, 2],
2642                  [3, --]],
2643            mask=[[ True, False],
2644                  [False,  True]],
2645            fill_value=999999)
2646          >>> x = x.reshape((4,1))
2647          >>> x
2648          masked_array(
2649            data=[[--],
2650                  [2],
2651                  [3],
2652                  [--]],
2653            mask=[[ True],
2654                  [False],
2655                  [False],
2656                  [ True]],
2657            fill_value=999999)
2658  
2659          r$r>r�)	r<rrMr�rOrBr�rSr�)r\r�r�r<rQr�r�r�r�1s:
2660  zMaskedArray.reshapecCsd}t|��)av
2661          .. warning::
2662  
2663              This method does nothing, except raise a ValueError exception. A
2664              masked array does not own its data and therefore cannot safely be
2665              resized in place. Use the `numpy.ma.resize` function instead.
2666  
2667          This method is difficult to implement safely and may be deprecated in
2668          future releases of NumPy.
2669  
2670          zoA masked array does not own its data and therefore cannot be resized.
2671  Use the numpy.ma.resize function instead.)r2)r\r��refcheckr$�errmsgr�r�r�r�ss
zMaskedArray.resize�raisecCs�|jr*|jtur*|j|}t|dd�}t|ddd�}|�|j�||}||}|jj|||d�|jtur@t|�tur@dSt	|�}t|�turS|j|d|d�n	|j||j|d�t
2672  |ddd�}||_dS)aD
2673          Set storage-indexed locations to corresponding values.
2674  
2675          Sets self._data.flat[n] = values[n] for each n in indices.
2676          If `values` is shorter than `indices` then it will repeat.
2677          If `values` has some masked values, the initial mask is updated
2678          in consequence, else the corresponding values are unmasked.
2679  
2680          Parameters
2681          ----------
2682          indices : 1-D array_like
2683              Target indices, interpreted as integers.
2684          values : array_like
2685              Values to place in self._data copy at target indices.
2686          mode : {'raise', 'wrap', 'clip'}, optional
2687              Specifies how out-of-bounds indices will behave.
2688              'raise' : raise an error.
2689              'wrap' : wrap around.
2690              'clip' : clip to the range.
2691  
2692          Notes
2693          -----
2694          `values` can be a scalar or length 1 array.
2695  
2696          Examples
2697          --------
2698          >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
2699          >>> x
2700          masked_array(
2701            data=[[1, --, 3],
2702                  [--, 5, --],
2703                  [7, --, 9]],
2704            mask=[[False,  True, False],
2705                  [ True, False,  True],
2706                  [False,  True, False]],
2707            fill_value=999999)
2708          >>> x.put([0,4,8],[10,20,30])
2709          >>> x
2710          masked_array(
2711            data=[[10, --, 3],
2712                  [--, 20, --],
2713                  [7, --, 30]],
2714            mask=[[False,  True, False],
2715                  [ True, False,  True],
2716                  [False,  True, False]],
2717            fill_value=999999)
2718  
2719          >>> x.put(4,999)
2720          >>> x
2721          masked_array(
2722            data=[[10, --, 3],
2723                  [--, 999, --],
2724                  [7, --, 30]],
2725            mask=[[False,  True, False],
2726                  [ True, False,  True],
2727                  [False,  True, False]],
2728            fill_value=999999)
2729  
2730          Fr�TrK��modeNr�)rrSr�rsr�r�rMr�rXrYrr)r\r`�valuesr�rQr�r�r�r�r��s"=
2731  
2732  
2733  zMaskedArray.putcCs,|jtur
|jjtt�fS|jj|jjjfS)a
2734          Return the addresses of the data and mask areas.
2735  
2736          Parameters
2737          ----------
2738          None
2739  
2740          Examples
2741          --------
2742          >>> x = np.ma.array([1, 2, 3], mask=[0, 1, 1])
2743          >>> x.ids()
2744          (166670640, 166659832) # may vary
2745  
2746          If the array has no mask, the address of `nomask` is returned. This address
2747          is typically not close to the data in memory:
2748  
2749          >>> x = np.ma.array([1, 2, 3])
2750          >>> x.ids()
2751          (166691080, 3083169284) # may vary
2752  
2753          )rSr��ctypesrP�idr}r�r�r�r_�s
2754  zMaskedArray.idscCs
2755  |jdS)a�
2756          Return a boolean indicating whether the data is contiguous.
2757  
2758          Parameters
2759          ----------
2760          None
2761  
2762          Examples
2763          --------
2764          >>> x = np.ma.array([1, 2, 3])
2765          >>> x.iscontiguous()
2766          True
2767  
2768          `iscontiguous` returns one of the flags of the masked array:
2769  
2770          >>> x.flags
2771            C_CONTIGUOUS : True
2772            F_CONTIGUOUS : True
2773            OWNDATA : False
2774            WRITEABLE : True
2775            ALIGNED : True
2776            WRITEBACKIFCOPY : False
2777  
27782779  CONTIGUOUS)rBr}r�r�r��iscontiguous�s
2780  zMaskedArray.iscontiguouscCs�|tjurind|i}t|j|fi|��}|dur;|�d�jdd|i|���t|��}|jr5|�	|�|S|r9t
2781  S|S|�d�jd||d�|��t|t�rX|jsS|rX|�	|�|S)a�
2782          Returns True if all elements evaluate to True.
2783  
2784          The output array is masked where all the values along the given axis
2785          are masked: if the output would have been a scalar and that all the
2786          values are masked, then the output is `masked`.
2787  
2788          Refer to `numpy.all` for full documentation.
2789  
2790          See Also
2791          --------
2792          numpy.ndarray.all : corresponding function for ndarrays
2793          numpy.all : equivalent function
2794  
2795          Examples
2796          --------
2797          >>> np.ma.array([1,2,3]).all()
2798          True
2799          >>> a = np.ma.array([1,2,3], mask=True)
2800          >>> (a.all() is np.ma.masked)
2801          True
2802  
2803          r�NTr�rtr�)
r�r	r�rSrMrrOrBr�rrvrr�r\r�rr�r�rQr�r�r�r�rs$
2804  �
2805  
2806  
2807  zMaskedArray.allcCs�|tjurind|i}t|j|fi|��}|dur;|�d�jdd|i|���t|��}|jr5|�	|�|S|r9t
2808  }|S|�d�jd||d�|��t|t�rX|jsS|rX|�	|�|S)aS
2809          Returns True if any of the elements of `a` evaluate to True.
2810  
2811          Masked values are considered as False during computation.
2812  
2813          Refer to `numpy.any` for full documentation.
2814  
2815          See Also
2816          --------
2817          numpy.ndarray.any : corresponding function for ndarrays
2818          numpy.any : equivalent function
2819  
2820          r�NFr�rtr�)
r�r	r�rSrMr rOrBr�rrvrrr�r�r�r�r 7s$
2821  �
2822  
2823  
2824  zMaskedArray.anycCst|�d�dd���S)a�
2825  
2826          Return the indices of unmasked elements that are not zero.
2827  
2828          Returns a tuple of arrays, one for each dimension, containing the
2829          indices of the non-zero elements in that dimension. The corresponding
2830          non-zero values can be obtained with::
2831  
2832              a[a.nonzero()]
2833  
2834          To group the indices by element, rather than dimension, use
2835          instead::
2836  
2837              np.transpose(a.nonzero())
2838  
2839          The result of this is always a 2d array, with a row for each non-zero
2840          element.
2841  
2842          Parameters
2843          ----------
2844          None
2845  
2846          Returns
2847          -------
2848          tuple_of_arrays : tuple
2849              Indices of elements that are non-zero.
2850  
2851          See Also
2852          --------
2853          numpy.nonzero :
2854              Function operating on ndarrays.
2855          flatnonzero :
2856              Return indices that are non-zero in the flattened version of the input
2857              array.
2858          numpy.ndarray.nonzero :
2859              Equivalent ndarray method.
2860          count_nonzero :
2861              Counts the number of non-zero elements in the input array.
2862  
2863          Examples
2864          --------
2865          >>> import numpy.ma as ma
2866          >>> x = ma.array(np.eye(3))
2867          >>> x
2868          masked_array(
2869            data=[[1., 0., 0.],
2870                  [0., 1., 0.],
2871                  [0., 0., 1.]],
2872            mask=False,
2873            fill_value=1e+20)
2874          >>> x.nonzero()
2875          (array([0, 1, 2]), array([0, 1, 2]))
2876  
2877          Masked elements are ignored.
2878  
2879          >>> x[1, 1] = ma.masked
2880          >>> x
2881          masked_array(
2882            data=[[1.0, 0.0, 0.0],
2883                  [0.0, --, 0.0],
2884                  [0.0, 0.0, 1.0]],
2885            mask=[[False, False, False],
2886                  [False,  True, False],
2887                  [False, False, False]],
2888            fill_value=1e+20)
2889          >>> x.nonzero()
2890          (array([0, 2]), array([0, 2]))
2891  
2892          Indices can also be grouped by element.
2893  
2894          >>> np.transpose(x.nonzero())
2895          array([[0, 0],
2896                 [2, 2]])
2897  
2898          A common use for ``nonzero`` is to find the indices of an array, where
2899          a condition is True.  Given an array `a`, the condition `a` > 3 is a
2900          boolean array and since False is interpreted as 0, ma.nonzero(a > 3)
2901          yields the indices of the `a` where the condition is true.
2902  
2903          >>> a = ma.array([[1,2,3],[4,5,6],[7,8,9]])
2904          >>> a > 3
2905          masked_array(
2906            data=[[False, False, False],
2907                  [ True,  True,  True],
2908                  [ True,  True,  True]],
2909            mask=False,
2910            fill_value=True)
2911          >>> ma.nonzero(a > 3)
2912          (array([1, 1, 1, 2, 2, 2]), array([0, 1, 2, 0, 1, 2]))
2913  
2914          The ``nonzero`` method of the condition array can also be called.
2915  
2916          >>> (a > 3).nonzero()
2917          (array([1, 1, 1, 2, 2, 2]), array([0, 1, 2, 0, 1, 2]))
2918  
2919          rFr�)rsrMr�r}r�r�r�r�Us`zMaskedArray.nonzeror�c	sV|j}|turt�j||||d�}|�|�S|j|||d�}|�|��d�jd|d�S)z8
2920          (this docstring should be overwritten)
2921          )�offset�axis1�axis2r)r�r�r�rr�rt)rSr�r�r�rErErMr�)	r\r�r�r�r	rr�r<r�r�r�r�r��s�
2922  zMaskedArray.tracecCst||||d�S)a�
2923          a.dot(b, out=None)
2924  
2925          Masked dot product of two arrays. Note that `out` and `strict` are
2926          located in different positions than in `ma.dot`. In order to
2927          maintain compatibility with the functional version, it is
2928          recommended that the optional arguments be treated as keyword only.
2929          At some point that may be mandatory.
2930  
2931          .. versionadded:: 1.10.0
2932  
2933          Parameters
2934          ----------
2935          b : masked_array_like
2936              Inputs array.
2937          out : masked_array, optional
2938              Output argument. This must have the exact kind that would be
2939              returned if it was not used. In particular, it must have the
2940              right type, must be C-contiguous, and its dtype must be the
2941              dtype that would be returned for `ma.dot(a,b)`. This is a
2942              performance feature. Therefore, if these conditions are not
2943              met, an exception is raised, instead of attempting to be
2944              flexible.
2945          strict : bool, optional
2946              Whether masked data are propagated (True) or set to 0 (False)
2947              for the computation. Default is False.  Propagating the mask
2948              means that if a masked value appears in a row or column, the
2949              whole row or column is considered masked.
2950  
2951              .. versionadded:: 1.10.2
2952  
2953          See Also
2954          --------
2955          numpy.ma.dot : equivalent function
2956  
2957          )r�strict)�dot)r\r�rrr�r�r�r�s%zMaskedArray.dotcCs�|tjurind|i}|j}t||fi|��}|durE|�d�j|fd|i|��}t|dd�}	|	r?|�t|��}|�	|�|S|rCt
2958  }|S|�d�j|f||d�|��}t|t�rlt
|�}
2959  |
2960  turit|j�}
2961  |_||
2962  _|S)aW
2963          Return the sum of the array elements over the given axis.
2964  
2965          Masked elements are set to 0 internally.
2966  
2967          Refer to `numpy.sum` for full documentation.
2968  
2969          See Also
2970          --------
2971          numpy.ndarray.sum : corresponding function for ndarrays
2972          numpy.sum : equivalent function
2973  
2974          Examples
2975          --------
2976          >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
2977          >>> x
2978          masked_array(
2979            data=[[1, --, 3],
2980                  [--, 5, --],
2981                  [7, --, 9]],
2982            mask=[[False,  True, False],
2983                  [ True, False,  True],
2984                  [False,  True, False]],
2985            fill_value=999999)
2986          >>> x.sum()
2987          25
2988          >>> x.sum(axis=1)
2989          masked_array(data=[4, 5, 16],
2990                       mask=[False, False, False],
2991                 fill_value=999999)
2992          >>> x.sum(axis=0)
2993          masked_array(data=[8, 5, 12],
2994                       mask=[False, False, False],
2995                 fill_value=999999)
2996          >>> print(type(x.sum(axis=0, dtype=np.int64)[0]))
2997          <class 'numpy.int64'>
2998  
2999          r�Nrr	r��r	r)r�r	rSr�rMr�r�rOrBrrvrrrXr�rtr�r�r\r�r	rr�r�rSr�r<Zrndim�outmaskr�r�r�r��s('
3000  �
3001  zMaskedArray.sumcCsV|�d�j|||d�}|durt|t�r|�|j�|S|�t|��}|�|j�|S)a
3002          Return the cumulative sum of the array elements over the given axis.
3003  
3004          Masked values are set to 0 internally during the computation.
3005          However, their position is saved, and the result will be masked at
3006          the same locations.
3007  
3008          Refer to `numpy.cumsum` for full documentation.
3009  
3010          Notes
3011          -----
3012          The mask is lost if `out` is not a valid :class:`ma.MaskedArray` !
3013  
3014          Arithmetic is modular when using integer types, and no error is
3015          raised on overflow.
3016  
3017          See Also
3018          --------
3019          numpy.ndarray.cumsum : corresponding function for ndarrays
3020          numpy.cumsum : equivalent function
3021  
3022          Examples
3023          --------
3024          >>> marr = np.ma.array(np.arange(10), mask=[0,0,0,1,1,1,0,0,0,0])
3025          >>> marr.cumsum()
3026          masked_array(data=[0, 1, 3, --, --, --, 9, 16, 24, 33],
3027                       mask=[False, False, False,  True,  True,  True, False, False,
3028                             False, False],
3029                 fill_value=999999)
3030  
3031          r�r�r	rN)	rMrBrrrrQrOrBrS�r\r�r	rr<r�r�r�rB+s 
3032  zMaskedArray.cumsumcCs�|tjurind|i}|j}t||fi|��}|durE|�d�j|fd|i|��}t|dd�}	|	r?|�t|��}|�	|�|S|rCt
3033  }|S|�d�j|f||d�|��}t|t�rlt
|�}
3034  |
3035  turit|j�}
3036  |_||
3037  _|S)a�
3038          Return the product of the array elements over the given axis.
3039  
3040          Masked elements are set to 1 internally for computation.
3041  
3042          Refer to `numpy.prod` for full documentation.
3043  
3044          Notes
3045          -----
3046          Arithmetic is modular when using integer types, and no error is raised
3047          on overflow.
3048  
3049          See Also
3050          --------
3051          numpy.ndarray.prod : corresponding function for ndarrays
3052          numpy.prod : equivalent function
3053          r�Nr�r	r�rr)r�r	rSr�rMr�r�rOrBrrvrrrXr�rtr�rrr�r�r�r�Ts(
3054  �
3055  zMaskedArray.prodcCsV|�d�j|||d�}|durt|t�r|�|j�|S|�t|��}|�|j�|S)a�
3056          Return the cumulative product of the array elements over the given axis.
3057  
3058          Masked values are set to 1 internally during the computation.
3059          However, their position is saved, and the result will be masked at
3060          the same locations.
3061  
3062          Refer to `numpy.cumprod` for full documentation.
3063  
3064          Notes
3065          -----
3066          The mask is lost if `out` is not a valid MaskedArray !
3067  
3068          Arithmetic is modular when using integer types, and no error is
3069          raised on overflow.
3070  
3071          See Also
3072          --------
3073          numpy.ndarray.cumprod : corresponding function for ndarrays
3074          numpy.cumprod : equivalent function
3075          r�rN)rMrArrrrSrOrBrr�r�r�rA~s
3076  zMaskedArray.cumprodcs<|tjurind|i}|jturt�jd||d�|��d}nZd}|durEt|jjt	j
3077  t	jf�r6t�d�}nt|jjt	j
�rEt�d�}d}|jd||d�|��}|jdd	|i|��}	|	jdkrf|	d
3078  krft}n|rs|j�|d|	�}n|d|	}|dur�||_t|t�r�t|�}
3079  |
3080  tur�t|j�}
3081  |_t|�|
3082  _|S|S)a�
3083          Returns the average of the array elements along given axis.
3084  
3085          Masked entries are ignored, and result elements which are not
3086          finite will be masked.
3087  
3088          Refer to `numpy.mean` for full documentation.
3089  
3090          See Also
3091          --------
3092          numpy.ndarray.mean : corresponding function for ndarrays
3093          numpy.mean : Equivalent function
3094          numpy.ma.average : Weighted average.
3095  
3096          Examples
3097          --------
3098          >>> a = np.ma.array([1,2,3], mask=[False, False, True])
3099          >>> a
3100          masked_array(data=[1, 2, --],
3101                       mask=[False, False,  True],
3102                 fill_value=999999)
3103          >>> a.mean()
3104          1.5
3105  
3106          r�r�r�FN�f8�f4Tr�rr�)r�r	rSr�r�r�rFr	rB�ntypes�integerr�mu�float16r�r@r�rvrrrrXrt)r\r�r	rr�r�r<�is_float16_resultZdsum�cntrr�r�r�r��s4
3107  
3108  
3109  
3110  zMaskedArray.meancCs&|�||�}|s||S|t||�S)a�
3111          Compute the anomalies (deviations from the arithmetic mean)
3112          along the given axis.
3113  
3114          Returns an array of anomalies, with the same shape as the input and
3115          where the arithmetic mean is computed along the given axis.
3116  
3117          Parameters
3118          ----------
3119          axis : int, optional
3120              Axis over which the anomalies are taken.
3121              The default is to use the mean of the flattened array as reference.
3122          dtype : dtype, optional
3123              Type to use in computing the variance. For arrays of integer type
3124               the default is float32; for arrays of float types it is the same as
3125               the array type.
3126  
3127          See Also
3128          --------
3129          mean : Compute the mean of the array.
3130  
3131          Examples
3132          --------
3133          >>> a = np.ma.array([1,2,3])
3134          >>> a.anom()
3135          masked_array(data=[-1.,  0.,  1.],
3136                       mask=False,
3137                 fill_value=1e+20)
3138  
3139          )r�r)r\r�r	r�r�r�r�r�szMaskedArray.anomcs�|tjurind|i}|jtur2t�jd||||d�|��d}|dur0t|t�r.|�t�|S|S|j	dd|i|��|}||j
3140  ||dd�}	t|�rTt�
|	�d}	n|	|	9}	t|	j|fi|��|��t|��}
3141  |
3142  jr�t|jj|fi|��|d	k�|
3143  _|
3144  �|�n+t|
3145  �r�t}
3146  |dur�t|t�r�d	|_|�d�|S|jjd
3147  vr�d}t|��tj|_|S|dur�|
3148  |_t|t�r�|�|
3149  j�|S|
3150  S)au
3151          Returns the variance of the array elements along given axis.
3152  
3153          Masked entries are ignored, and result elements which are not
3154          finite will be masked.
3155  
3156          Refer to `numpy.var` for full documentation.
3157  
3158          See Also
3159          --------
3160          numpy.ndarray.var : corresponding function for ndarrays
3161          numpy.var : Equivalent function
3162          r�)r�r	r�ddofr�Nr�T�r�rSr�biu�>Masked data information would be lost in one or more location.)r�r	rSr�r�r�rrrr@r�rrbrrGr�rOrBr�rurr�rXrvrr	rrr�rQ)r\r�r	rrr�r�r�rZdanom�dvarr�r�r�r�r��sN
3163  ��
3164  
3165  " 
3166  
3167  �
3168  zMaskedArray.varcCs`|tjurind|i}|j||||fi|��}|tur.|dur*tj|d|dd�|St|�}|S)a>
3169          Returns the standard deviation of the array elements along given axis.
3170  
3171          Masked entries are ignored.
3172  
3173          Refer to `numpy.std` for full documentation.
3174  
3175          See Also
3176          --------
3177          numpy.ndarray.std : corresponding function for ndarrays
3178          numpy.std : Equivalent function
3179          r�Ng�?r��rr�)r�r	r�rvr�r�)r\r�r	rrr�r�rr�r�r�r�9szMaskedArray.stdcCsh|jj||d��t|��}|jdkr|j|_|�|�n|jr!t}|dur'|St|t	�r2|�
3180  |j�|S)a
3181          Return each element rounded to the given number of decimals.
3182  
3183          Refer to `numpy.around` for full documentation.
3184  
3185          See Also
3186          --------
3187          numpy.ndarray.round : corresponding function for ndarrays
3188          numpy.around : equivalent function
3189          )�decimalsrrN)rMr�rOrBr�rSr�rvrrr)r\rrr<r�r�r�r�Qs
3190  
3191  zMaskedArray.roundcCsb|tjur	t|�}|dur$|r t�|jtj�rtj}n	t|�}nt|�}|�	|�}|j
3192  |||d�S)a!	
3193          Return an ndarray of indices that sort the array along the
3194          specified axis.  Masked values are filled beforehand to
3195          `fill_value`.
3196  
3197          Parameters
3198          ----------
3199          axis : int, optional
3200              Axis along which to sort. If None, the default, the flattened array
3201              is used.
3202  
3203              ..  versionchanged:: 1.13.0
3204                  Previously, the default was documented to be -1, but that was
3205                  in error. At some future date, the default will change to -1, as
3206                  originally intended.
3207                  Until then, the axis should be given explicitly when
3208                  ``arr.ndim > 1``, to avoid a FutureWarning.
3209          kind : {'quicksort', 'mergesort', 'heapsort', 'stable'}, optional
3210              The sorting algorithm used.
3211          order : list, optional
3212              When `a` is an array with fields defined, this argument specifies
3213              which fields to compare first, second, etc.  Not all fields need be
3214              specified.
3215          endwith : {True, False}, optional
3216              Whether missing values (if any) should be treated as the largest values
3217              (True) or the smallest values (False)
3218              When the array contains unmasked values at the same extremes of the
3219              datatype, the ordering of these values and the masked values is
3220              undefined.
3221          fill_value : scalar or None, optional
3222              Value used internally for the masked values.
3223              If ``fill_value`` is not None, it supersedes ``endwith``.
3224  
3225          Returns
3226          -------
3227          index_array : ndarray, int
3228              Array of indices that sort `a` along the specified axis.
3229              In other words, ``a[index_array]`` yields a sorted `a`.
3230  
3231          See Also
3232          --------
3233          ma.MaskedArray.sort : Describes sorting algorithms used.
3234          lexsort : Indirect stable sort with multiple keys.
3235          numpy.ndarray.sort : Inplace sort.
3236  
3237          Notes
3238          -----
3239          See `sort` for notes on the different sorting algorithms.
3240  
3241          Examples
3242          --------
3243          >>> a = np.ma.array([3,2,1], mask=[False, False, True])
3244          >>> a
3245          masked_array(data=[3, 2, --],
3246                       mask=[False, False,  True],
3247                 fill_value=999999)
3248          >>> a.argsort()
3249          array([1, 0, 2])
3250  
3251          N�r�rr$)r�r	r�r�r	r�r�r�r�rMr,)r\r�rr$�endwithr6rMr�r�r�r,js
3252  @
3253  
3254  zMaskedArray.argsortrcCsF|durt|�}|�|��t�}|tjurdnt|�}|j|||d�S)a<
3255          Return array of indices to the minimum values along the given axis.
3256  
3257          Parameters
3258          ----------
3259          axis : {None, integer}
3260              If None, the index is into the flattened array, otherwise along
3261              the specified axis
3262          fill_value : scalar or None, optional
3263              Value used to fill in the masked values.  If None, the output of
3264              minimum_fill_value(self._data) is used instead.
3265          out : {None, array}, optional
3266              Array into which the result can be placed. Its type is preserved
3267              and it must be of the right shape to hold the output.
3268  
3269          Returns
3270          -------
3271          ndarray or scalar
3272              If multi-dimension input, returns a new ndarray of indices to the
3273              minimum values along the given axis.  Otherwise, returns a scalar
3274              of index to the minimum values along the given axis.
3275  
3276          Examples
3277          --------
3278          >>> x = np.ma.array(np.arange(4), mask=[1,1,0,0])
3279          >>> x.shape = (2,2)
3280          >>> x
3281          masked_array(
3282            data=[[--, --],
3283                  [2, 3]],
3284            mask=[[ True,  True],
3285                  [False, False]],
3286            fill_value=999999)
3287          >>> x.argmin(axis=0, fill_value=-1)
3288          array([0, 0])
3289          >>> x.argmin(axis=0, fill_value=9)
3290          array([1, 1])
3291  
3292          NF�rr�)r�rMrOrr�r	r�r+�r\r�r6rr�r�r�r�r�r+�s
3293  )zMaskedArray.argmincCsH|dur	t|j�}|�|��t�}|tjurdnt|�}|j|||d�S)a�
3294          Returns array of indices of the maximum values along the given axis.
3295          Masked values are treated as if they had the value fill_value.
3296  
3297          Parameters
3298          ----------
3299          axis : {None, integer}
3300              If None, the index is into the flattened array, otherwise along
3301              the specified axis
3302          fill_value : scalar or None, optional
3303              Value used to fill in the masked values.  If None, the output of
3304              maximum_fill_value(self._data) is used instead.
3305          out : {None, array}, optional
3306              Array into which the result can be placed. Its type is preserved
3307              and it must be of the right shape to hold the output.
3308  
3309          Returns
3310          -------
3311          index_array : {integer_array}
3312  
3313          Examples
3314          --------
3315          >>> a = np.arange(6).reshape(2,3)
3316          >>> a.argmax()
3317          5
3318          >>> a.argmax(0)
3319          array([1, 1, 1])
3320          >>> a.argmax(1)
3321          array([2, 2])
3322  
3323          NFr)	r�rMrMrOrr�r	r�r*rr�r�r�r*�s
3324  !
3325  zMaskedArray.argmaxr�cCsX|jturtj||||d�dS|turdS|j|||||d�}tj|||d�|d<dS)a
3326  
3327  
3328          Sort the array, in-place
3329  
3330          Parameters
3331          ----------
3332          a : array_like
3333              Array to be sorted.
3334          axis : int, optional
3335              Axis along which to sort. If None, the array is flattened before
3336              sorting. The default is -1, which sorts along the last axis.
3337          kind : {'quicksort', 'mergesort', 'heapsort', 'stable'}, optional
3338              The sorting algorithm used.
3339          order : list, optional
3340              When `a` is a structured array, this argument specifies which fields
3341              to compare first, second, and so on.  This list does not need to
3342              include all of the fields.
3343          endwith : {True, False}, optional
3344              Whether missing values (if any) should be treated as the largest values
3345              (True) or the smallest values (False)
3346              When the array contains unmasked values sorting at the same extremes of the
3347              datatype, the ordering of these values and the masked values is
3348              undefined.
3349          fill_value : scalar or None, optional
3350              Value used internally for the masked values.
3351              If ``fill_value`` is not None, it supersedes ``endwith``.
3352  
3353          Returns
3354          -------
3355          sorted_array : ndarray
3356              Array of the same type and shape as `a`.
3357  
3358          See Also
3359          --------
3360          numpy.ndarray.sort : Method to sort an array in-place.
3361          argsort : Indirect sort.
3362          lexsort : Indirect stable sort on multiple keys.
3363          searchsorted : Find elements in a sorted array.
3364  
3365          Notes
3366          -----
3367          See ``sort`` for notes on the different sorting algorithms.
3368  
3369          Examples
3370          --------
3371          >>> a = np.ma.array([1, 2, 5, 4, 3],mask=[0, 1, 0, 1, 0])
3372          >>> # Default
3373          >>> a.sort()
3374          >>> a
3375          masked_array(data=[1, 3, 5, --, --],
3376                       mask=[False, False, False,  True,  True],
3377                 fill_value=999999)
3378  
3379          >>> a = np.ma.array([1, 2, 5, 4, 3],mask=[0, 1, 0, 1, 0])
3380          >>> # Put missing values in the front
3381          >>> a.sort(endwith=False)
3382          >>> a
3383          masked_array(data=[--, --, 1, 3, 5],
3384                       mask=[ True,  True, False, False, False],
3385                 fill_value=999999)
3386  
3387          >>> a = np.ma.array([1, 2, 5, 4, 3],mask=[0, 1, 0, 1, 0])
3388          >>> # fill_value takes over endwith
3389          >>> a.sort(endwith=False, fill_value=3)
3390          >>> a
3391          masked_array(data=[1, --, --, 3, 5],
3392                       mask=[False,  True,  True, False, False],
3393                 fill_value=999999)
3394  
3395          rN)r�rr$r6rrT.)rSr�rr�rvr,r��take_along_axis)r\r�rr$rr6�sidxr�r�r�r�s
3396  G
3397  �zMaskedArray.sortcC�"|tjurind|i}|j}t||fi|��}|durt|�}|durR|�|�jd||d�|���t|��}|j	rL|�
3398  |�|j	rJtj||j|d�|S|rPt
}|S|�|�jd||d�|��}t|t�rzt|�}	|	turut|j�}	|_||	_|S|jjdvr�d}
3399  t|
3400  ��tj|tj|d�|S)as	
3401          Return the minimum along a given axis.
3402  
3403          Parameters
3404          ----------
3405          axis : None or int or tuple of ints, optional
3406              Axis along which to operate.  By default, ``axis`` is None and the
3407              flattened input is used.
3408              .. versionadded:: 1.7.0
3409              If this is a tuple of ints, the minimum is selected over multiple
3410              axes, instead of a single axis or all the axes as before.
3411          out : array_like, optional
3412              Alternative output array in which to place the result.  Must be of
3413              the same shape and buffer length as the expected output.
3414          fill_value : scalar or None, optional
3415              Value used to fill in the masked values.
3416              If None, use the output of `minimum_fill_value`.
3417          keepdims : bool, optional
3418              If this is set to True, the axes which are reduced are left
3419              in the result as dimensions with size one. With this option,
3420              the result will broadcast correctly against the array.
3421  
3422          Returns
3423          -------
3424          amin : array_like
3425              New array holding the result.
3426              If ``out`` was specified, ``out`` is returned.
3427  
3428          See Also
3429          --------
3430          ma.minimum_fill_value
3431              Returns the minimum filling value for a given datatype.
3432  
3433          Examples
3434          --------
3435          >>> import numpy.ma as ma
3436          >>> x = [[1., -2., 3.], [0.2, -0.7, 0.1]]
3437          >>> mask = [[1, 1, 0], [0, 0, 1]]
3438          >>> masked_x = ma.masked_array(x, mask)
3439          >>> masked_x
3440          masked_array(
3441            data=[[--, --, 3.0],
3442                  [0.2, -0.7, --]],
3443            mask=[[ True,  True, False],
3444                  [False, False,  True]],
3445            fill_value=1e+20)
3446          >>> ma.min(masked_x)
3447          -0.7
3448          >>> ma.min(masked_x, axis=-1)
3449          masked_array(data=[3.0, -0.7],
3450                       mask=[False, False],
3451                  fill_value=1e+20)
3452          >>> ma.min(masked_x, axis=0, keepdims=True)
3453          masked_array(data=[[0.2, -0.7, 3.0]],
3454                       mask=[[False, False, False]],
3455                  fill_value=1e+20)
3456          >>> mask = [[1, 1, 1,], [1, 1, 1]]
3457          >>> masked_x = ma.masked_array(x, mask)
3458          >>> ma.min(masked_x, axis=0)
3459          masked_array(data=[--, --, --],
3460                       mask=[ True,  True,  True],
3461                  fill_value=1e+20,
3462                      dtype=float64)
3463          r�Nrtr�rrr�)r�r	rSr�r�rMr�rOrBr�rr�r6rvrrrXr�rtr�rr	rrr��r\r�rr6r�r�rSr�r<rr�r�r�r�r�csBA��
3464  �
3465  �
3466  �zMaskedArray.mincCr)a�	
3467          Return the maximum along a given axis.
3468  
3469          Parameters
3470          ----------
3471          axis : None or int or tuple of ints, optional
3472              Axis along which to operate.  By default, ``axis`` is None and the
3473              flattened input is used.
3474              .. versionadded:: 1.7.0
3475              If this is a tuple of ints, the maximum is selected over multiple
3476              axes, instead of a single axis or all the axes as before.
3477          out : array_like, optional
3478              Alternative output array in which to place the result.  Must
3479              be of the same shape and buffer length as the expected output.
3480          fill_value : scalar or None, optional
3481              Value used to fill in the masked values.
3482              If None, use the output of maximum_fill_value().
3483          keepdims : bool, optional
3484              If this is set to True, the axes which are reduced are left
3485              in the result as dimensions with size one. With this option,
3486              the result will broadcast correctly against the array.
3487  
3488          Returns
3489          -------
3490          amax : array_like
3491              New array holding the result.
3492              If ``out`` was specified, ``out`` is returned.
3493  
3494          See Also
3495          --------
3496          ma.maximum_fill_value
3497              Returns the maximum filling value for a given datatype.
3498  
3499          Examples
3500          --------
3501          >>> import numpy.ma as ma
3502          >>> x = [[-1., 2.5], [4., -2.], [3., 0.]]
3503          >>> mask = [[0, 0], [1, 0], [1, 0]]
3504          >>> masked_x = ma.masked_array(x, mask)
3505          >>> masked_x
3506          masked_array(
3507            data=[[-1.0, 2.5],
3508                  [--, -2.0],
3509                  [--, 0.0]],
3510            mask=[[False, False],
3511                  [ True, False],
3512                  [ True, False]],
3513            fill_value=1e+20)
3514          >>> ma.max(masked_x)
3515          2.5
3516          >>> ma.max(masked_x, axis=0)
3517          masked_array(data=[-1.0, 2.5],
3518                       mask=[False, False],
3519                 fill_value=1e+20)
3520          >>> ma.max(masked_x, axis=1, keepdims=True)
3521          masked_array(
3522            data=[[2.5],
3523                  [-2.0],
3524                  [0.0]],
3525            mask=[[False],
3526                  [False],
3527                  [False]],
3528            fill_value=1e+20)
3529          >>> mask = [[1, 1], [1, 1], [1, 1]]
3530          >>> masked_x = ma.masked_array(x, mask)
3531          >>> ma.max(masked_x, axis=1)
3532          masked_array(data=[--, --, --],
3533                       mask=[ True,  True,  True],
3534                 fill_value=1e+20,
3535                      dtype=float64)
3536          r�Nrtr�rrr�)r�r	rSr�r�rMr�rOrBr�rr�r6rvrrrXr�rtr�rr	rrr�rr�r�r�r��sBH��
3537  �
3538  �
3539  �zMaskedArray.maxcCsj|dur|j|||d�}||j|||d�8}|S|j||||d�|_|j|||d�}tj|||dd�|S)a�
3540  
3541          Return (maximum - minimum) along the given dimension
3542          (i.e. peak-to-peak value).
3543  
3544          .. warning::
3545              `ptp` preserves the data type of the array. This means the
3546              return value for an input of signed integers with n bits
3547              (e.g. `np.int8`, `np.int16`, etc) is also a signed integer
3548              with n bits.  In that case, peak-to-peak values greater than
3549              ``2**(n-1)-1`` will be returned as negative values. An example
3550              with a work-around is shown below.
3551  
3552          Parameters
3553          ----------
3554          axis : {None, int}, optional
3555              Axis along which to find the peaks.  If None (default) the
3556              flattened array is used.
3557          out : {None, array_like}, optional
3558              Alternative output array in which to place the result. It must
3559              have the same shape and buffer length as the expected output
3560              but the type will be cast if necessary.
3561          fill_value : scalar or None, optional
3562              Value used to fill in the masked values.
3563          keepdims : bool, optional
3564              If this is set to True, the axes which are reduced are left
3565              in the result as dimensions with size one. With this option,
3566              the result will broadcast correctly against the array.
3567  
3568          Returns
3569          -------
3570          ptp : ndarray.
3571              A new array holding the result, unless ``out`` was
3572              specified, in which case a reference to ``out`` is returned.
3573  
3574          Examples
3575          --------
3576          >>> x = np.ma.MaskedArray([[4, 9, 2, 10],
3577          ...                        [6, 9, 7, 12]])
3578  
3579          >>> x.ptp(axis=1)
3580          masked_array(data=[8, 6],
3581                       mask=False,
3582                 fill_value=999999)
3583  
3584          >>> x.ptp(axis=0)
3585          masked_array(data=[2, 0, 5, 2],
3586                       mask=False,
3587                 fill_value=999999)
3588  
3589          >>> x.ptp()
3590          10
3591  
3592          This example shows that a negative value can be returned when
3593          the input is an array of signed integers.
3594  
3595          >>> y = np.ma.MaskedArray([[1, 127],
3596          ...                        [0, 127],
3597          ...                        [-1, 127],
3598          ...                        [-2, 127]], dtype=np.int8)
3599          >>> y.ptp(axis=1)
3600          masked_array(data=[ 126,  127, -128, -127],
3601                       mask=False,
3602                 fill_value=999999,
3603                      dtype=int8)
3604  
3605          A work-around is to use the `view()` method to view the result as
3606          unsigned integers with the same bit width:
3607  
3608          >>> y.ptp(axis=1).view(np.uint8)
3609          masked_array(data=[126, 127, 128, 129],
3610                       mask=False,
3611                 fill_value=999999,
3612                      dtype=uint8)
3613          N)r�r6r�)r�rr6r�r�r)r�r�rr�r�)r\r�rr6r�r<�	min_valuer�r�r�r�1s K�
3614  �
3615  ��zMaskedArray.ptpc�,tjd|jj�d�dd�t�j|i|��S)Nz3Warning: 'partition' will ignore the 'mask' of the rrSr�)r�r�r�r�r��	partition�r\r�r�r�r�r�r ����zMaskedArray.partitioncr)Nz6Warning: 'argpartition' will ignore the 'mask' of the rrSr�)r�r�r�r�r��argpartitionr!r�r�r�r#�r"zMaskedArray.argpartitionc
3616  Cs�|j|j}}t|�}t|�}|tur|�d�}|dur*|j|||d�d�|�}n
3617  tj|||||d�t	|t
3618  �rQ|tur@|}	n|j|||d�}	|	|O}	|�|	�|dS)z	
3619          rN)r�r�.)r�r�rr�)rMrSrBrXr�rMr�rOr�rrr)
3620  r\r`r�rr�rMrSrIZmaskindicesrr�r�r�r��s
3621  
3622  
3623  zMaskedArray.taker<rE�flattenr�r�r�cCs|��Sr)r�r}r�r�r��<lambda>�szMaskedArray.<lambda>r�cCs�|j}|tur|j��S|dur|�|���S|jj}|r9|j�dd�|D��}|D]
3624  }d||||<q*|��S|tur@dgS|j}t	j
3625  |j��td�}d||��<||_|��S)aP
3626          Return the data portion of the masked array as a hierarchical Python list.
3627  
3628          Data items are converted to the nearest compatible Python type.
3629          Masked values are converted to `fill_value`. If `fill_value` is None,
3630          the corresponding entries in the output list will be ``None``.
3631  
3632          Parameters
3633          ----------
3634          fill_value : scalar, optional
3635              The value to use for invalid entries. Default is None.
3636  
3637          Returns
3638          -------
3639          result : list
3640              The Python list representation of the masked array.
3641  
3642          Examples
3643          --------
3644          >>> x = np.ma.array([[1,2,3], [4,5,6], [7,8,9]], mask=[0] + [1,0]*4)
3645          >>> x.tolist()
3646          [[1, None, 3], [None, 5, None], [7, None, 9]]
3647          >>> x.tolist(-999)
3648          [[1, -999, 3], [-999, 5, -999], [7, -999, 9]]
3649  
3650          NcSsg|]}|tf�qSr�)r3r�r�r�r�r��rDz&MaskedArray.tolist.<locals>.<listcomp>r)
rSr�rM�tolistrMr	rrEr�r�r
3651  r�r3)r\r6rSrr<rbr
3652  r�r�r�r&�s$
3653  zMaskedArray.tolistcCstjdtdd�|j||d�S)z�
3654          A compatibility alias for `tobytes`, with exactly the same behavior.
3655  
3656          Despite its name, it returns `bytes` not `str`\ s.
3657  
3658          .. deprecated:: 1.19.0
3659          z0tostring() is deprecated. Use tobytes() instead.rSr�r�)r�r�rr�tobytes�r\r6r$r�r�r��tostring�s
3660  	�zMaskedArray.tostringcCs|�|�j|d�S)a�
3661          Return the array data as a string containing the raw bytes in the array.
3662  
3663          The array is filled with a fill value before the string conversion.
3664  
3665          .. versionadded:: 1.9.0
3666  
3667          Parameters
3668          ----------
3669          fill_value : scalar, optional
3670              Value used to fill in the masked values. Default is None, in which
3671              case `MaskedArray.fill_value` is used.
3672          order : {'C','F','A'}, optional
3673              Order of the data item in the copy. Default is 'C'.
3674  
3675              - 'C'   -- C order (row major).
3676              - 'F'   -- Fortran order (column major).
3677              - 'A'   -- Any, current order of array.
3678              - None  -- Same as 'A'.
3679  
3680          See Also
3681          --------
3682          numpy.ndarray.tobytes
3683          tolist, tofile
3684  
3685          Notes
3686          -----
3687          As for `ndarray.tobytes`, information about the shape, dtype, etc.,
3688          but also about `fill_value`, will be lost.
3689  
3690          Examples
3691          --------
3692          >>> x = np.ma.array(np.array([[1, 2], [3, 4]]), mask=[[0, 1], [1, 0]])
3693          >>> x.tobytes()
3694          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'
3695  
3696          r�)rMr'r(r�r�r�r'�s&zMaskedArray.tobytesr��%scCrf)z�
3697          Save a masked array to a file in binary format.
3698  
3699          .. warning::
3700            This function is not implemented yet.
3701  
3702          Raises
3703          ------
3704          NotImplementedError
3705              When `tofile` is called.
3706  
3707          z)MaskedArray.tofile() not implemented yet.rg)r\�fid�sepr�r�r�r��tofile#s
zMaskedArray.tofilecCs\|j}|j}|durt|j|�}|jj}tj|jd|fd|fgd�}|j|d<|j|d<|S)a�
3708          Transforms a masked array into a flexible-type array.
3709  
3710          The flexible type array that is returned will have two fields:
3711  
3712          * the ``_data`` field stores the ``_data`` part of the array.
3713          * the ``_mask`` field stores the ``_mask`` part of the array.
3714  
3715          Parameters
3716          ----------
3717          None
3718  
3719          Returns
3720          -------
3721          record : ndarray
3722              A new flexible-type `ndarray` with two fields: the first element
3723              containing a value, the second element containing the corresponding
3724              mask boolean. The returned record shape matches self.shape.
3725  
3726          Notes
3727          -----
3728          A side-effect of transforming a masked array into a flexible `ndarray` is
3729          that meta information (``fill_value``, ...) will be lost.
3730  
3731          Examples
3732          --------
3733          >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
3734          >>> x
3735          masked_array(
3736            data=[[1, --, 3],
3737                  [--, 5, --],
3738                  [7, --, 9]],
3739            mask=[[False,  True, False],
3740                  [ True, False,  True],
3741                  [False,  True, False]],
3742            fill_value=999999)
3743          >>> x.toflex()
3744          array([[(1, False), (2,  True), (3, False)],
3745                 [(4,  True), (5, False), (6,  True)],
3746                 [(7, False), (8,  True), (9, False)]],
3747                dtype=[('_data', '<i8'), ('_mask', '?')])
3748  
3749          NrMrS)r�r	)r	rSrtr�r�rrM)r\�ddtyperSr+�recordr�r�r��toflex2s-�
3750  
3751  zMaskedArray.toflexcs2d|jj}t���d}|t|��|�|jfS)zWReturn the internal state of the masked array, for pickling
3752          purposes.
3753  
3754          �CFrS)rB�fncr��
3755  __reduce__rYr'r0)r\�cfZ
3756  data_stater�r�r��__getstate__oszMaskedArray.__getstate__c	sH|\}}}}}}}t��||||f�|j�|t|�||f�||_dS)akRestore the internal state of the masked array, for
3757          pickling purposes.  ``state`` is typically the output of the
3758          ``__getstate__`` output, and is a 5-tuple:
3759  
3760          - class name
3761          - a tuple giving the shape of the data
3762          - a typecode for the data
3763          - a binary string for the data
3764          - a binary string for the mask.
3765  
3766          N)r��__setstate__rSrsr6)	r\�stater��shp�typ�isf�raw�msk�flvr�r�r�r6xs
3767  zMaskedArray.__setstate__cCst|j|jddf|��fS)z6Return a 3-tuple for pickling a MaskedArray.
3768  
3769          r�r�)�_mareconstructr�r&r5r}r�r�r�r3�s�zMaskedArray.__reduce__cCs`ddlm}tjt|�|dd�}|duri}||t|�<|j��D]\}}|||�|j|<q!|S)Nr)�deepcopyTr�)r<r?rr7rBr�r:r�)r\�memor?�copiedr��vr�r�r��__deepcopy__�szMaskedArray.__deepcopy__r)NNN�F�NN�r>)TF�r�)rrr�NN)NFr��r�NNTN)NNNF�NNr�)Nr>)r�r*)�r�r�r�r�r�r�Z_defaultmaskZ_defaulthardmaskrr&rvrwr7r�rFrMrOrr�propertyr	�setterr�r�	_set_maskrQrer\r�rrkrlr�rnrorMrPrr6rpr=�fsetr�rMr8r7r{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�r�r�r��get_imagr��get_realr�r	r@r�r�r�r�r_r�rr r�r�rr�rBr�r�rAr�rr�r�r�r,r+r*r�r�r�r�r r#r�rr<rEr$r�r�r��Tr�r&r)r'r-r0Z	torecordsr5r6r3rCr�r�r�r�r�r�
3770  sLd
3771  �
3772  ]
3773  8Z~F
3774  E
3775  	
3776  
3777  
3778  
3779  +
3780  
3781  
3782  
3783  
3784  
3785  
3786  (
3787  P
3788  HTE
								

3789  
3790  
3791  c6
3792  B
3793  U(b
3794  
3795  '
3796  >)(
3797  
3798  7%�
3799  >
38003801  
3802  �P�/�'
3803  �Sc
3804  kX
3805  
3806  
3807  3
3808  
3809  (:	rcCs2t�|||�}t�t|t|��}|j||||d�S)zbInternal function that builds a new MaskedArray from the
3810      information stored in a pickle.
3811  
3812      )rQr	)rr7rs)rrn�	baseshape�basetyperMrSr�r�r�r>�sr>cs|eZdZdZedddddfdd�Ze�fdd��Zd	d
3813  �Zdd�Z	�fd
d�Z
3814  e
3815  Zdd�Zdd�Z
ddd�Zdd�Z�ZS)r�zN
3816      Fake a 'void' object to use for masked array with structured dtypes.
3817      NFTc
3818  Cs�tj||||d�}|�|�}||_|tur?t|tj�r||_n zt�|�|_Wnty>t	|�}	tj||	d�d|_Ynw|durF||_
3819  |S)N)r<rLr	rr�)r�r
3820  rOrr�rr1rSr�rsr6)
3821  r\rPrQr	r6rr<rLrMr+r�r�r�r7�s
3822  �z
mvoid.__new__cst�jdS)Nr�)r�rMr}r�r�r�rM�szmvoid._datacCsT|j}t||t�rt|j||||j||jd�S|tur%||r%tS|j|S)z!
3823          Get the index.
3824  
3825          )rPrQr6r3)	rSrrrwrMr0rr�rv)r\rr�r�r�r�r�s�
3826  zmvoid.__getitem__cCsD||j|<|jr|j|t|dd�O<dSt|dd�|j|<dS)NrSF)rMrrSr�)r\rr�r�r�r�r�s
3827  zmvoid.__setitem__csN|j}|turt|j�St|jjd�}t�j}|�|�}t||jt	�t|�S)Nr�)
3828  rSr�rrMr�r	r�rEr�r�)r\r�rzZdata_arrr�r�r�r�r~�s
3829  
3830  z
mvoid.__str__ccsP�|j|j}}|tur|EdHdSt||�D]
\}}|r"tVq|VqdS)zDefines an iterator for mvoidN)rMrSr�r)rv)r\rMrSr�r�r�r�r�r��s��zmvoid.__iter__cCrcr)rM�__len__r}r�r�r�rS�roz
mvoid.__len__cCst|��|�dS)aA
3831          Return a copy with masked fields filled with a given value.
3832  
3833          Parameters
3834          ----------
3835          fill_value : array_like, optional
3836              The value to use for invalid entries. Can be scalar or
3837              non-scalar. If latter is the case, the filled array should
3838              be broadcastable over input array. Default is None, in
3839              which case the `fill_value` attribute is used instead.
3840  
3841          Returns
3842          -------
3843          filled_void
3844              A `np.void` object
3845  
3846          See Also
3847          --------
3848          MaskedArray.filled
3849  
3850          r�)r/rM)r\r6r�r�r�rM�szmvoid.filledcCsZ|j}|tur|j��Sg}t|j|j�D]\}}|r!|�d�q|�|���qt|�S)z�
3851      Transforms the mvoid object into a tuple.
3852  
3853      Masked fields are replaced by None.
3854  
3855      Returns
3856      -------
3857      returned_tuple
3858          Tuple of fields
3859          N)rSr�rMr&r)r!r+r
)r\rSr<r�r�r�r�r�r&s
3860  zmvoid.tolistr)r�r�r�r�r�r7rJrMrrr~r�r�rSrMr&r�r�r�r�r�r��s
3861  �
3862  r�cCr�)a�
3863      Test whether input is an instance of MaskedArray.
3864  
3865      This function returns True if `x` is an instance of MaskedArray
3866      and returns False otherwise.  Any object is accepted as input.
3867  
3868      Parameters
3869      ----------
3870      x : object
3871          Object to test.
3872  
3873      Returns
3874      -------
3875      result : bool
3876          True if `x` is a MaskedArray.
3877  
3878      See Also
3879      --------
3880      isMA : Alias to isMaskedArray.
3881      isarray : Alias to isMaskedArray.
3882  
3883      Examples
3884      --------
3885      >>> import numpy.ma as ma
3886      >>> a = np.eye(3, 3)
3887      >>> a
3888      array([[ 1.,  0.,  0.],
3889             [ 0.,  1.,  0.],
3890             [ 0.,  0.,  1.]])
3891      >>> m = ma.masked_values(a, 0)
3892      >>> m
3893      masked_array(
3894        data=[[1.0, --, --],
3895              [--, 1.0, --],
3896              [--, --, 1.0]],
3897        mask=[[False,  True,  True],
3898              [ True, False,  True],
3899              [ True,  True, False]],
3900        fill_value=0.0)
3901      >>> ma.isMaskedArray(a)
3902      False
3903      >>> ma.isMaskedArray(m)
3904      True
3905      >>> ma.isMaskedArray([0, 1, 2])
3906      False
3907  
3908      )rr�rdr�r�r�rd2s
3909  0rdcs�eZdZdZedd��Zdd�Z�fdd�Zddd	�Zdd
3910  d�Z	dd
�Z
3911  dd�Zdd�Zdd�Z
dd�ZeZZZZZZ[dd�Zdd�Zdd�Z�fdd�Z�ZS)rENcCs|jduot|j�|uSr)�_MaskedConstant__singletonrB)rIr�r�r�Z__has_singletonmszMaskedConstant.__has_singletoncCsF|��s t�d�}t�d�}d|j_d|j_t||d��|�|_|jS)Nr�TFr�)�_MaskedConstant__has_singletonr�r
3912  rB�	writeablerrOrU)rIrPrQr�r�r�r7ss
3913  
3914  zMaskedConstant.__new__cs8|��s
3915  t��|�S||jurdSt|_t�||�dSr)rVr�rFrUrr�)r\r�r�r�r�rF�s
3916  z!MaskedConstant.__array_finalize__cC�|�t��||�Sr)rOr�__array_prepare__�r\r�rJr�r�r�rY��z MaskedConstant.__array_prepare__cCrXr)rOrrMrZr�r�r�rM�r[zMaskedConstant.__array_wrap__cCs
3917  ttj�Sr)rr�r�r}r�r�r�r~�rozMaskedConstant.__str__cCs|tjurdSt�|�S)Nrv)rErUr3r�r}r�r�r�r��s
3918  
3919  zMaskedConstant.__repr__cCs>zt�||�WStytjdtdd�t�|d�YSw)NzjFormat strings passed to MaskedConstant are ignored, but in future may error or produce different behaviorrSr�r�)r3�
3920  __format__r�r�r��
FutureWarning)r\�format_specr�r�r�r\�s��zMaskedConstant.__format__cCs
3921  |jdfS)z.Override of MaskedArray's __reduce__.
3922          r�r�r}r�r�r�r3�s
3923  zMaskedConstant.__reduce__cCrrr�r�r�r�r��__iop__�rzMaskedConstant.__iop__cOr)z: Copy is a no-op on the maskedconstant, as it is a scalar r�r!r�r�r�r<�szMaskedConstant.copycCrrr�r}r�r�r��__copy__�rzMaskedConstant.__copy__cCrrr�)r\r@r�r�r�rC�rzMaskedConstant.__deepcopy__cs>|��st��||�S||jurtd|�d���t��||�S)Nzattributes of z are not writeable)rVr��__setattr__rUrN)r\�attrr�r�r�r�ra�s
3924  
3925  �zMaskedConstant.__setattr__r)r�r�r�rU�classmethodrVr7rFrYrMr~r�r\r3r_r�r�r�r�r�r�r<r`rCrar�r�r�r�r�rEis8
3926  
3927  
3928  ����rEc
Cst|||||	||||
3929  ||d�S)z~
3930      Shortcut to MaskedArray.
3931  
3932      The options are in a different order for convenience and backwards
3933      compatibility.
3934  
3935      )
3936  rQr	r<rLr2r3r6r%r�r$)r)rPr	r<r$rQr6r2r3r�rLr%r�r�r�r
3937  �s
3938  
3939  
3940  �r
3941  cCs$t|�}|tur
3942  dS|��rdSdS)a
3943      Determine whether input has masked values.
3944  
3945      Accepts any object as input, but always returns False unless the
3946      input is a MaskedArray containing masked values.
3947  
3948      Parameters
3949      ----------
3950      x : array_like
3951          Array to check for masked values.
3952  
3953      Returns
3954      -------
3955      result : bool
3956          True if `x` is a MaskedArray with masked values, False otherwise.
3957  
3958      Examples
3959      --------
3960      >>> import numpy.ma as ma
3961      >>> x = ma.masked_equal([0, 1, 0, 2, 3], 0)
3962      >>> x
3963      masked_array(data=[--, 1, --, 2, 3],
3964                   mask=[ True, False,  True, False, False],
3965             fill_value=0)
3966      >>> ma.is_masked(x)
3967      True
3968      >>> x = ma.masked_equal([0, 1, 0, 2, 3], 42)
3969      >>> x
3970      masked_array(data=[0, 1, 0, 2, 3],
3971                   mask=False,
3972             fill_value=42)
3973      >>> ma.is_masked(x)
3974      False
3975  
3976      Always returns False if `x` isn't a MaskedArray.
3977  
3978      >>> x = [False, True, False]
3979      >>> ma.is_masked(x)
3980      False
3981      >>> x = 'a string'
3982      >>> ma.is_masked(x)
3983      False
3984  
3985      FT)rXr�r )rdr�r�r�r�rf�s-rfcs>eZdZdZ�fdd�Zdd�Zejfdd�Zdd	�Z	�Z
3986  S)
3987  �_extrema_operationz�
3988      Generic class for maximum/minimum functions.
3989  
3990      .. note::
3991        This is the base class for `_maximum_operation` and
3992        `_minimum_operation`.
3993  
3994      cst��|�||_||_dSr)r�r]r��fill_value_func)r\r|r�r6r�r�r�r]5s
3995  z_extrema_operation.__init__cCst|�||�||�S)rl)r�r�r[r�r�r�re:sz_extrema_operation.__call__cCs�t|ddd�}t|�}|tjur(|jdkr(tjd|j�d|j�d�tdd	�d
3996  }|tjur3t	|d�}nt	�}|t
3997  urF|jj|fi|��}|S|�
|�|���t|��}|jj|fi|��}tjj|fi|��}t|d�rq||_|S|rut}|S)
z#Reduce target along the given axis.FTrKr�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.rSr�NrTrS)rsrXr�r	r�r�r�r�r�r@r�r�rrMrerOrBrbrnrrSrv)r\r�r�r�r�r�r�r�r�r?s:
3998  ��
3999  
4000  ��
4001  �
4002  �z_extrema_operation.reducecCsvt|�}t|�}|tur|turt}nt|�}t|�}t�||�}|j�t|�t|��}t|t�s6|�	t�}||_
4003  |S)z<Return the function applied to the outer product of a and b.)rXr�rYrpr�r�rMrrrOrS)r\r;r�r�r�r�r<r�r�r�r�_s
4004  
4005  z_extrema_operation.outer)r�r�r�r�r]rer�r	rr�r�r�r�r�r�rd,s rdc	C�d|tjurind|i}z
|jd|||d�|��WSttfy1t|�jd|||d�|��YSw�Nr��r�r6rr�)r�r	r�rNr�r.�r�r�rr6r�r�r�r�r�r�o��
4006  ��r�c	Crfrg)r�r	r�rNr�r.rir�r�r�r�{rjr�c	Csd|tjurind|i}z
|j|f||d�|��WSttfy1t|�jd|||d�|��YSw)Nr�)rr6rhr�)r�r	r�rNr�r.rir�r�r�r��s�
4007  ��r�c@s*eZdZdZd
4008  dd�Zdd�Zdd�Zd	S)�_frommethodz�
4009      Define functions from existing MaskedArray methods.
4010  
4011      Parameters
4012      ----------
4013      methodname : str
4014          Name of the method to transform.
4015  
4016      FcCs||_|��|_||_dSr)r��getdocr��reversed)r\�
4017  methodnamermr�r�r�r]�s
4018  
4019  z_frommethod.__init__cCsNtt|jd�p
tt|jd�}|jt|�}|dur%d|t|dd�f}|SdS)�<Return the doc of the function (from the doc of the method).Nz	    %s
4020  %sr�)r�rr�r�r�)r\�meth�	signature�docr�r�r�rl�s���z_frommethod.getdoccOsf|jrt|�}|d|}|d<t|�}|j}tt|�|d�}|dur(tt|�}||g|�Ri|��Sr�)rmrUr.r�r�rBr�)r\r;r�r
�marr�method_name�methodr�r�r�re�s
4021  z_frommethod.__call__NrD)r�r�r�r�r]rlrer�r�r�r�rk�s
4022  
4023  
4024  
4025  rkrrr r7)rmrArBr<rEr\r_r�r�r�r�r�r�r�r�r�r�r�r�r@r�cCst|�}|j||||d�S)z
4026      )r�rr�)rwr�)r;r`r�rr�r�r�r�r��sr�c	Cs|durtd��t|�}t|�}t||�}t|�}t|�}t|t�r't|�}nt}tjddd��t�	||t
4027  �||���|�}	Wd�n1sIwY|	�
|�t�t�|	�t���}
4028  |turn|	jsgtSt�||
4029  �|	_|
4030  ��r�|	jswtS|	jtur|
4031  |	_|	j|	j|
4032  <|	S)a�
4033      Returns element-wise base array raised to power from second array.
4034  
4035      This is the masked array version of `numpy.power`. For details see
4036      `numpy.power`.
4037  
4038      See Also
4039      --------
4040      numpy.power
4041  
4042      Notes
4043      -----
4044      The *out* argument to `numpy.power` is not supported, `third` has to be
4045      None.
4046  
4047      Examples
4048      --------
4049      >>> import numpy.ma as ma
4050      >>> x = [11.2, -3.973, 0.801, -1.41]
4051      >>> mask = [0, 0, 0, 1]
4052      >>> masked_x = ma.masked_array(x, mask)
4053      >>> masked_x
4054      masked_array(data=[11.2, -3.973, 0.801, --],
4055               mask=[False, False, False,  True],
4056         fill_value=1e+20)
4057      >>> ma.power(masked_x, 2)
4058      masked_array(data=[125.43999999999998, 15.784728999999999,
4059                     0.6416010000000001, --],
4060               mask=[False, False, False,  True],
4061         fill_value=1e+20)
4062      >>> y = [-0.5, 2, 0, 17]
4063      >>> masked_y = ma.masked_array(y, mask)
4064      >>> masked_y
4065      masked_array(data=[-0.5, 2.0, 0.0, --],
4066               mask=[False, False, False,  True],
4067         fill_value=1e+20)
4068      >>> ma.power(masked_x, masked_y)
4069      masked_array(data=[0.29880715233359845, 15.784728999999999, 1.0, --],
4070               mask=[False, False, False,  True],
4071         fill_value=1e+20)
4072  
4073      Nz3-argument power not supported.r_r�)rrXrurWrrrBr�rar�rbr�rOr�rorRrr�r�rvrprSr r6rM)r;r��thirdr�r�r��fa�fbrRr<rTr�r�r�r��s4+
4074  
4075  
4076  �
4077  
4078  r�r+r*cCsJt�|�}|tjurt|�}t|t�r|j|||||d�S|j|||d�S)z)Function version of the eponymous method.�r�rr$rr6r)r�r.r	r�rrr,�r;r�rr$rr6r�r�r�r,6s
4079  
4080  
4081  
4082  �r,r�cCsZtj|ddd�}|dur|��}d}t|t�r#|j|||||d�|S|j|||d�|S)a
4083      Return a sorted copy of the masked array.
4084  
4085      Equivalent to creating a copy of the array
4086      and applying the  MaskedArray ``sort()`` method.
4087  
4088      Refer to ``MaskedArray.sort`` for the full documentation
4089  
4090      See Also
4091      --------
4092      MaskedArray.sort : equivalent method
4093      TrKNrryr)r�r
4094  r$rrr�rzr�r�r�r�Es

4095  
4096  ��r�cCst|���S)a
4097      Return all the non-masked data as a 1-D array.
4098  
4099      This function is equivalent to calling the "compressed" method of a
4100      `ma.MaskedArray`, see `ma.MaskedArray.compressed` for details.
4101  
4102      See Also
4103      --------
4104      ma.MaskedArray.compressed : Equivalent method.
4105  
4106      )r.r8rTr�r�r�r8_sr8cCsvt�dd�|D�|�}t|�}|�|�}|D]
4107  }t|�tur nq|St�dd�|D�|�}|�|j�}t|�|_	|S)aI
4108      Concatenate a sequence of arrays along the given axis.
4109  
4110      Parameters
4111      ----------
4112      arrays : sequence of array_like
4113          The arrays must have the same shape, except in the dimension
4114          corresponding to `axis` (the first, by default).
4115      axis : int, optional
4116          The axis along which the arrays will be joined. Default is 0.
4117  
4118      Returns
4119      -------
4120      result : MaskedArray
4121          The concatenated array with any masked entries preserved.
4122  
4123      See Also
4124      --------
4125      numpy.concatenate : Equivalent function in the top-level NumPy module.
4126  
4127      Examples
4128      --------
4129      >>> import numpy.ma as ma
4130      >>> a = ma.arange(3)
4131      >>> a[1] = ma.masked
4132      >>> b = ma.arange(2, 5)
4133      >>> a
4134      masked_array(data=[0, --, 2],
4135                   mask=[False,  True, False],
4136             fill_value=999999)
4137      >>> b
4138      masked_array(data=[2, 3, 4],
4139                   mask=False,
4140             fill_value=999999)
4141      >>> ma.concatenate([a, b])
4142      masked_array(data=[0, --, 2, 2, 3, 4],
4143                   mask=[False,  True, False, False, False, False],
4144             fill_value=999999)
4145  
4146      cSrAr�)rWrCr�r�r�r��rDzconcatenate.<locals>.<listcomp>cSrAr�rGrCr�r�r�r��rD)
4147  r�r9rJrOrXr�r�r�r�rS)rGr�r�rHrPrd�dmr�r�r�r9ns)
4148  �
4149  r9cCs2t�||��t�}t|�turt�|j|�|_|S)a
4150      Extract a diagonal or construct a diagonal array.
4151  
4152      This function is the equivalent of `numpy.diag` that takes masked
4153      values into account, see `numpy.diag` for details.
4154  
4155      See Also
4156      --------
4157      numpy.diag : Equivalent function for ndarrays.
4158  
4159      )r�rDrOrrXr�rS)rBr�r�r�r�r�rD�srDcC�Ft|�}|turt�t|�|�}t|�St�t|d�|�}t||d�S)z�
4160      Shift the bits of an integer to the left.
4161  
4162      This is the masked array version of `numpy.left_shift`, for details
4163      see that function.
4164  
4165      See Also
4166      --------
4167      numpy.left_shift
4168  
4169      rr�)rXr�rbrhrMrw�r;rbr�r�r�r�r�rh��rhcCr|)z�
4170      Shift the bits of an integer to the right.
4171  
4172      This is the masked array version of `numpy.right_shift`, for details
4173      see that function.
4174  
4175      See Also
4176      --------
4177      numpy.right_shift
4178  
4179      rr�)rXr�rbr�rMrwr}r�r�r�r��r~r�cCs>z	|j|||d�WStyt|dd�j|||d�YSw)z�
4180      Set storage-indexed locations to corresponding values.
4181  
4182      This function is equivalent to `MaskedArray.put`, see that method
4183      for details.
4184  
4185      See Also
4186      --------
4187      MaskedArray.put
4188  
4189      r�Fr�)r�rNrs)r;r`r�r�r�r�r�r��s
4190  
�r�cCs�t|t�s
4191  |�t�}t|�t|�}}t|�tur2|tur1d|_t|j|j	�|_
4192  tj|j
4193  ||d�n-|j
rN|turM|j
4194  ��}tj|||d�|j|O_n|turVt|�}tj|j
4195  ||d�tj|j||d�dS)aQ
4196      Changes elements of an array based on conditional and input values.
4197  
4198      This is the masked array version of `numpy.putmask`, for details see
4199      `numpy.putmask`.
4200  
4201      See Also
4202      --------
4203      numpy.putmask
4204  
4205      Notes
4206      -----
4207      Using a masked array as `values` will **not** transform a `ndarray` into
4208      a `MaskedArray`.
4209  
4210      Tr�N)rrrOrWrXr�r1rtr�r	rSr�r�rr<rQrYrM)r;rQr�ZvaldataZvalmaskr�r�r�r�r��s(
4211  
4212  �
4213  �r�cCs8z|�|�WStyt|dd��|��t�YSw)a�
4214      Permute the dimensions of an array.
4215  
4216      This function is exactly equivalent to `numpy.transpose`.
4217  
4218      See Also
4219      --------
4220      numpy.transpose : Equivalent function in top-level NumPy module.
4221  
4222      Examples
4223      --------
4224      >>> import numpy.ma as ma
4225      >>> x = ma.arange(4).reshape((2,2))
4226      >>> x[1, 1] = ma.masked
4227      >>> x
4228      masked_array(
4229        data=[[0, 1],
4230              [2, --]],
4231        mask=[[False, False],
4232              [False,  True]],
4233        fill_value=999999)
4234  
4235      >>> ma.transpose(x)
4236      masked_array(
4237        data=[[0, 2],
4238              [1, --]],
4239        mask=[[False, False],
4240              [False,  True]],
4241        fill_value=999999)
4242      Fr�)r�rNrsrOr)r;r�r�r�r�r� s
4243   �r�r>cCsDz|j||d�WSty!t|dd�j||d�}|�t�YSw)z�
4244      Returns an array containing the same data with a new shape.
4245  
4246      Refer to `MaskedArray.reshape` for full documentation.
4247  
4248      See Also
4249      --------
4250      MaskedArray.reshape : equivalent function
4251  
4252      r�Fr�)r�rNrsrOr)r;�	new_shaper$�_tmpr�r�r�r�Fs�r�cCsBt|�}|turt�||�}t�||��t|��}|jr||_|S)a
4253      Return a new masked array with the specified size and shape.
4254  
4255      This is the masked equivalent of the `numpy.resize` function. The new
4256      array is filled with repeated copies of `x` (in the order that the
4257      data are stored in memory). If `x` is masked, the new array will be
4258      masked, and the new mask will be a repetition of the old one.
4259  
4260      See Also
4261      --------
4262      numpy.resize : Equivalent function in the top level NumPy module.
4263  
4264      Examples
4265      --------
4266      >>> import numpy.ma as ma
4267      >>> a = ma.array([[1, 2] ,[3, 4]])
4268      >>> a[0, 1] = ma.masked
4269      >>> a
4270      masked_array(
4271        data=[[1, --],
4272              [3, 4]],
4273        mask=[[False,  True],
4274              [False, False]],
4275        fill_value=999999)
4276      >>> np.resize(a, (3, 3))
4277      masked_array(
4278        data=[[1, 2, 3],
4279              [4, 1, 2],
4280              [3, 4, 1]],
4281        mask=False,
4282        fill_value=999999)
4283      >>> ma.resize(a, (3, 3))
4284      masked_array(
4285        data=[[1, --, 3],
4286              [4, 1, --],
4287              [3, 4, 1]],
4288        mask=[[False,  True, False],
4289              [False, False,  True],
4290              [False, False, False]],
4291        fill_value=999999)
4292  
4293      A MaskedArray is always returned, regardless of the input type.
4294  
4295      >>> a = np.array([[1, 2] ,[3, 4]])
4296      >>> ma.resize(a, (3, 3))
4297      masked_array(
4298        data=[[1, 2, 3],
4299              [4, 1, 2],
4300              [3, 4, 1]],
4301        mask=False,
4302        fill_value=999999)
4303  
4304      )rXr�r�r�rOrJr�rS)rdrr�r<r�r�r�r�Ys7r�cC�t�t|��S)z5
4305      maskedarray version of the numpy function.
4306  
4307      )r�r�rWrr�r�r�r��sr�cCr���*maskedarray version of the numpy function.)r�r�rWrr�r�r�r��rdr�cCst�t|�|�Sr�)r�r�rW)r�r�r�r�r�r��sr�cCs|tu|tuf�d�}|dkrtd��|dkrt|�St|d�}t|�}t|�}t|�}t|�}t|�}	|turM|turMtj	d|j
4308  d�}tjd|	j
4309  d�}n|ture|turetj	d|j
4310  d�}tjd|j
4311  d�}	t�|||�}
4312  t�|||	�}t�|tjd|j
4313  d�|�}t
|�}t|
4314  |d�S)	a�
4315      Return a masked array with elements from `x` or `y`, depending on condition.
4316  
4317      .. note::
4318          When only `condition` is provided, this function is identical to
4319          `nonzero`. The rest of this documentation covers only the case where
4320          all three arguments are provided.
4321  
4322      Parameters
4323      ----------
4324      condition : array_like, bool
4325          Where True, yield `x`, otherwise yield `y`.
4326      x, y : array_like, optional
4327          Values from which to choose. `x`, `y` and `condition` need to be
4328          broadcastable to some shape.
4329  
4330      Returns
4331      -------
4332      out : MaskedArray
4333          An masked array with `masked` elements where the condition is masked,
4334          elements from `x` where `condition` is True, and elements from `y`
4335          elsewhere.
4336  
4337      See Also
4338      --------
4339      numpy.where : Equivalent function in the top-level NumPy module.
4340      nonzero : The function that is called when x and y are omitted
4341  
4342      Examples
4343      --------
4344      >>> x = np.ma.array(np.arange(9.).reshape(3, 3), mask=[[0, 1, 0],
4345      ...                                                    [1, 0, 1],
4346      ...                                                    [0, 1, 0]])
4347      >>> x
4348      masked_array(
4349        data=[[0.0, --, 2.0],
4350              [--, 4.0, --],
4351              [6.0, --, 8.0]],
4352        mask=[[False,  True, False],
4353              [ True, False,  True],
4354              [False,  True, False]],
4355        fill_value=1e+20)
4356      >>> np.ma.where(x > 5, x, -3.1416)
4357      masked_array(
4358        data=[[-3.1416, --, -3.1416],
4359              [--, -3.1416, --],
4360              [6.0, --, 8.0]],
4361        mask=[[False,  True, False],
4362              [ True, False,  True],
4363              [False,  True, False]],
4364        fill_value=1e+20)
4365  
4366      Tr�z)Must provide both 'x' and 'y' or neither.rSFr�rr�)r	r@r2r�rMrWrYrvr�r�r	r�r�r�rw)r�rdrq�missingr4�xdZyd�cm�xm�ymrPrQr�r�r�r��s,8
4367  r�c	s�dd��dd��t|d�}�fdd�|D�}�fdd�|D�}tj|||d	�}tt|t|��d
4368  dd�}tj||||d
��t�}|durOt|t�rM|�	|�|S|�	|�|S)aH
4369      Use an index array to construct a new array from a list of choices.
4370  
4371      Given an array of integers and a list of n choice arrays, this method
4372      will create a new array that merges each of the choice arrays.  Where a
4373      value in `index` is i, the new array will have the value that choices[i]
4374      contains in the same place.
4375  
4376      Parameters
4377      ----------
4378      indices : ndarray of ints
4379          This array must contain integers in ``[0, n-1]``, where n is the
4380          number of choices.
4381      choices : sequence of arrays
4382          Choice arrays. The index array and all of the choices should be
4383          broadcastable to the same shape.
4384      out : array, optional
4385          If provided, the result will be inserted into this array. It should
4386          be of the appropriate shape and `dtype`.
4387      mode : {'raise', 'wrap', 'clip'}, optional
4388          Specifies how out-of-bounds indices will behave.
4389  
4390          * 'raise' : raise an error
4391          * 'wrap' : wrap around
4392          * 'clip' : clip to the range
4393  
4394      Returns
4395      -------
4396      merged_array : array
4397  
4398      See Also
4399      --------
4400      choose : equivalent function
4401  
4402      Examples
4403      --------
4404      >>> choice = np.array([[1,1,1], [2,2,2], [3,3,3]])
4405      >>> a = np.array([2, 1, 0])
4406      >>> np.ma.choose(a, choice)
4407      masked_array(data=[3, 2, 1],
4408                   mask=False,
4409             fill_value=999999)
4410  
4411      cS�|turdSt|�S)z,Returns the filled array, or True if masked.T)rvrMrTr�r�r��fmask<�zchoose.<locals>.fmaskcSr�)z:Returns the mask, True if ``masked``, False if ``nomask``.T)rvrXrTr�r�r��nmaskBr�zchoose.<locals>.nmaskrc�g|]}�|��qSr�r��r�rd)r�r�r�r�JrDzchoose.<locals>.<listcomp>cr�r�r�r�)r�r�r�r�KrDr�FTr�)r�rN)
4412  rMr�r4rrrurXrOrrr)	r`�choicesrr�r��masksrP�
4413  outputmaskr�r�)r�r�r�r4s -
4414  �
4415  
4416  
4417  r4cCs@|durt�|||�St�t|�||�t|d�rt|�|_|S)a�
4418      Return a copy of a, rounded to 'decimals' places.
4419  
4420      When 'decimals' is negative, it specifies the number of positions
4421      to the left of the decimal point.  The real and imaginary parts of
4422      complex numbers are rounded separately. Nothing is done if the
4423      array is not of float type and 'decimals' is greater than or equal
4424      to 0.
4425  
4426      Parameters
4427      ----------
4428      decimals : int
4429          Number of decimals to round to. May be negative.
4430      out : array_like
4431          Existing array to use for output.
4432          If not given, returns a default copy of a.
4433  
4434      Notes
4435      -----
4436      If out is given and does not have a mask attribute, the mask of a
4437      is lost!
4438  
4439      Examples
4440      --------
4441      >>> import numpy.ma as ma
4442      >>> x = [11.2, -3.973, 0.801, -1.41]
4443      >>> mask = [0, 0, 0, 1]
4444      >>> masked_x = ma.masked_array(x, mask)
4445      >>> masked_x
4446      masked_array(data=[11.2, -3.973, 0.801, --],
4447                   mask=[False, False, False, True],
4448          fill_value=1e+20)
4449      >>> ma.round_(masked_x)
4450      masked_array(data=[11.0, -4.0, 1.0, --],
4451                   mask=[False, False, False, True],
4452          fill_value=1e+20)
4453      >>> ma.round(masked_x, decimals=1)
4454      masked_array(data=[11.2, -4.0, 0.8, --],
4455                   mask=[False, False, False, True],
4456          fill_value=1e+20)
4457      >>> ma.round_(masked_x, decimals=-1)
4458      masked_array(data=[10.0, -0.0, 0.0, --],
4459                   mask=[False, False, False, True],
4460          fill_value=1e+20)
4461      NrS)r�r�rWrrXrS)r;rrr�r�r�r�Zs.
4462  
4463  r�cCs�t|dd�}|jdkrtd��t|�}|tus|��s|S|��}|j��|_|s2t	|t
4464  �|d�<|dvrCt	|dd�t
4465  �|d�f<|S)	a�
4466      Mask rows and/or columns of a 2D array that contain masked values.
4467  
4468      Mask whole rows and/or columns of a 2D array that contain
4469      masked values.  The masking behavior is selected using the
4470      `axis` parameter.
4471  
4472        - If `axis` is None, rows *and* columns are masked.
4473        - If `axis` is 0, only rows are masked.
4474        - If `axis` is 1 or -1, only columns are masked.
4475  
4476      Parameters
4477      ----------
4478      a : array_like, MaskedArray
4479          The array to mask.  If not a MaskedArray instance (or if no array
4480          elements are masked).  The result is a MaskedArray with `mask` set
4481          to `nomask` (False). Must be a 2D array.
4482      axis : int, optional
4483          Axis along which to perform the operation. If None, applies to a
4484          flattened version of the array.
4485  
4486      Returns
4487      -------
4488      a : MaskedArray
4489          A modified version of the input array, masked depending on the value
4490          of the `axis` parameter.
4491  
4492      Raises
4493      ------
4494      NotImplementedError
4495          If input array `a` is not 2D.
4496  
4497      See Also
4498      --------
4499      mask_rows : Mask rows of a 2D array that contain masked values.
4500      mask_cols : Mask cols of a 2D array that contain masked values.
4501      masked_where : Mask where a condition is met.
4502  
4503      Notes
4504      -----
4505      The input array's mask is modified by this function.
4506  
4507      Examples
4508      --------
4509      >>> import numpy.ma as ma
4510      >>> a = np.zeros((3, 3), dtype=int)
4511      >>> a[1, 1] = 1
4512      >>> a
4513      array([[0, 0, 0],
4514             [0, 1, 0],
4515             [0, 0, 0]])
4516      >>> a = ma.masked_equal(a, 1)
4517      >>> a
4518      masked_array(
4519        data=[[0, 0, 0],
4520              [0, --, 0],
4521              [0, 0, 0]],
4522        mask=[[False, False, False],
4523              [False,  True, False],
4524              [False, False, False]],
4525        fill_value=1)
4526      >>> ma.mask_rowcols(a)
4527      masked_array(
4528        data=[[0, --, 0],
4529              [--, --, --],
4530              [0, --, 0]],
4531        mask=[[False,  True, False],
4532              [ True,  True,  True],
4533              [False,  True, False]],
4534        fill_value=1)
4535  
4536      Fr�rSz&mask_rowcols works for 2D arrays only.r)Nr�r�Nr�)r
4537  r�rXrXr�r r�rSr<rvr��unique)r;r�r�Z	maskedvalr�r�r��mask_rowcols�sI
4538  r�c	Cs�|r|jdkr|jdkrt|d�}t|d�}t|�}t|�}|durPt�t|d�t|d��}t�||�}|jdkrAt�|�}|�t||��}|�	|�|St�t|d�t|d�|j
4539  �}|jj|jkrmt�
|jt�|_t�|||j�t�|j|j�|S)a�
4540      Return the dot product of two arrays.
4541  
4542      This function is the equivalent of `numpy.dot` that takes masked values
4543      into account. Note that `strict` and `out` are in different position
4544      than in the method version. In order to maintain compatibility with the
4545      corresponding method, it is recommended that the optional arguments be
4546      treated as keyword only.  At some point that may be mandatory.
4547  
4548      .. note::
4549        Works only with 2-D arrays at the moment.
4550  
4551  
4552      Parameters
4553      ----------
4554      a, b : masked_array_like
4555          Inputs arrays.
4556      strict : bool, optional
4557          Whether masked data are propagated (True) or set to 0 (False) for
4558          the computation. Default is False.  Propagating the mask means that
4559          if a masked value appears in a row or column, the whole row or
4560          column is considered masked.
4561      out : masked_array, optional
4562          Output argument. This must have the exact kind that would be returned
4563          if it was not used. In particular, it must have the right type, must be
4564          C-contiguous, and its dtype must be the dtype that would be returned
4565          for `dot(a,b)`. This is a performance feature. Therefore, if these
4566          conditions are not met, an exception is raised, instead of attempting
4567          to be flexible.
4568  
4569          .. versionadded:: 1.10.2
4570  
4571      See Also
4572      --------
4573      numpy.dot : Equivalent function for ndarrays.
4574  
4575      Examples
4576      --------
4577      >>> a = np.ma.array([[1, 2, 3], [4, 5, 6]], mask=[[1, 0, 0], [0, 0, 0]])
4578      >>> b = np.ma.array([[1, 2], [3, 4], [5, 6]], mask=[[1, 0], [0, 0], [0, 0]])
4579      >>> np.ma.dot(a, b)
4580      masked_array(
4581        data=[[21, 26],
4582              [45, 64]],
4583        mask=[[False, False],
4584              [False, False]],
4585        fill_value=999999)
4586      >>> np.ma.dot(a, b, strict=True)
4587      masked_array(
4588        data=[[--, --],
4589              [--, 64]],
4590        mask=[[ True,  True],
4591              [ True, False]],
4592        fill_value=999999)
4593  
4594      rSrr�N)r�r�rYr�rrMr/rOrJrrMrQr�rHrrSro)	r;r�rr�am�bmr�r�r�r�r�r�r�s&;
4595  
4596  
4597  
4598  
4599  
4600  
4601  rcCsFt|d�}t|d�}|jdkrd|_|jdkrd|_t�||��t�S)z�
4602      Returns the inner product of a and b for arrays of floating point types.
4603  
4604      Like the generic NumPy equivalent the product sum is over the last dimension
4605      of a and b. The first argument is not conjugated.
4606  
4607      rr�)rMr�r�r�rarOr)r;r�rwrxr�r�r�raBs
4608  
4609  
4610  
4611  raz Masked values are replaced by 0.cCs�t|d���}t|d���}t�||�}t|�}t|�}|tur(|tur(t|�St|�}t|�}tdt�d|d|�dd�}t||d�S)r�rr�Fr�r�)	rMr�r�r�rXr�rwrYrr)r;r�rwrxr�r�r�r�r�r�r�r�Vs r�cCs�|r0|t|�tjt�|�td�|d�|tjt�|�td�t|�|d�B}|t|�t|�|d�}n|t|�t|��}|t|d�t|d�|d�}t||d�S)z:
4612      Helper function for ma.correlate and ma.convolve
4613      rr�rr�)rYr�r�r�r�rWrMrw)r�r;rBr��propagate_maskrQrPr�r�r��_convolve_or_correlatehs  ��r��validcC�ttj||||�S)a�
4614      Cross-correlation of two 1-dimensional sequences.
4615  
4616      Parameters
4617      ----------
4618      a, v : array_like
4619          Input sequences.
4620      mode : {'valid', 'same', 'full'}, optional
4621          Refer to the `np.convolve` docstring.  Note that the default
4622          is 'valid', unlike `convolve`, which uses 'full'.
4623      propagate_mask : bool
4624          If True, then a result element is masked if any masked element contributes towards it.
4625          If False, then a result element is only masked if no non-masked element
4626          contribute towards it
4627  
4628      Returns
4629      -------
4630      out : MaskedArray
4631          Discrete cross-correlation of `a` and `v`.
4632  
4633      See Also
4634      --------
4635      numpy.correlate : Equivalent function in the top-level NumPy module.
4636      )r�r�r=�r;rBr�r�r�r�r�r={�r=rcCr�)a�
4637      Returns the discrete, linear convolution of two one-dimensional sequences.
4638  
4639      Parameters
4640      ----------
4641      a, v : array_like
4642          Input sequences.
4643      mode : {'valid', 'same', 'full'}, optional
4644          Refer to the `np.convolve` docstring.
4645      propagate_mask : bool
4646          If True, then if any masked element is included in the sum for a result
4647          element, then the result is masked.
4648          If False, then the result element is only masked if no non-masked cells
4649          contribute towards it
4650  
4651      Returns
4652      -------
4653      out : MaskedArray
4654          Discrete, linear convolution of `a` and `v`.
4655  
4656      See Also
4657      --------
4658      numpy.convolve : Equivalent function in the top-level NumPy module.
4659      )r�r�r;r�r�r�r�r;�r�r;cCs�tt|�t|��}|turt|�}t|�}t�||�}|��S|r>t|�}t|�}t�||�}t||dd�}|�d��d�SdS)a
4660      Return True if all entries of a and b are equal, using
4661      fill_value as a truth value where either or both are masked.
4662  
4663      Parameters
4664      ----------
4665      a, b : array_like
4666          Input arrays to compare.
4667      fill_value : bool, optional
4668          Whether masked values in a or b are considered equal (True) or not
4669          (False).
4670  
4671      Returns
4672      -------
4673      y : bool
4674          Returns True if the two arrays are equal within the given
4675          tolerance, False otherwise. If either array contains NaN,
4676          then False is returned.
4677  
4678      See Also
4679      --------
4680      all, any
4681      numpy.ma.allclose
4682  
4683      Examples
4684      --------
4685      >>> a = np.ma.array([1e10, 1e-7, 42.0], mask=[0, 0, 1])
4686      >>> a
4687      masked_array(data=[10000000000.0, 1e-07, --],
4688                   mask=[False, False,  True],
4689             fill_value=1e+20)
4690  
4691      >>> b = np.array([1e10, 1e-7, -42.0])
4692      >>> b
4693      array([  1.00000000e+10,   1.00000000e-07,  -4.20000000e+01])
4694      >>> np.ma.allequal(a, b, fill_value=False)
4695      False
4696      >>> np.ma.allequal(a, b)
4697      True
4698  
4699      F)rQr<TN)	rurXr�rWrbrJrr
4700  rM)r;r�r6r�rdrqr�r{r�r�r�r�s*rcCs,t|dd�}t|dd�}|jjdkr$t�|d�}|j|kr$t||dd�}tt|�t|��}t�t|d|d���d�}	t�	|	tt�|�d�k�sIdSt�
4701  |	�settt||�||t|��|�}
4702  t�	|
4703  �St�	t||	||	k|��sudS||	}||	}ttt||�||t|��|�}
4704  t�	|
4705  �S)aL
4706      Returns True if two arrays are element-wise equal within a tolerance.
4707  
4708      This function is equivalent to `allclose` except that masked values
4709      are treated as equal (default) or unequal, depending on the `masked_equal`
4710      argument.
4711  
4712      Parameters
4713      ----------
4714      a, b : array_like
4715          Input arrays to compare.
4716      masked_equal : bool, optional
4717          Whether masked values in `a` and `b` are considered equal (True) or not
4718          (False). They are considered equal by default.
4719      rtol : float, optional
4720          Relative tolerance. The relative difference is equal to ``rtol * b``.
4721          Default is 1e-5.
4722      atol : float, optional
4723          Absolute tolerance. The absolute difference is equal to `atol`.
4724          Default is 1e-8.
4725  
4726      Returns
4727      -------
4728      y : bool
4729          Returns True if the two arrays are equal within the given
4730          tolerance, False otherwise. If either array contains NaN, then
4731          False is returned.
4732  
4733      See Also
4734      --------
4735      all, any
4736      numpy.allclose : the non-masked `allclose`.
4737  
4738      Notes
4739      -----
4740      If the following equation is element-wise True, then `allclose` returns
4741      True::
4742  
4743        absolute(`a` - `b`) <= (`atol` + `rtol` * absolute(`b`))
4744  
4745      Return True if all elements of `a` and `b` are equal subject to
4746      given tolerances.
4747  
4748      Examples
4749      --------
4750      >>> a = np.ma.array([1e10, 1e-7, 42.0], mask=[0, 0, 1])
4751      >>> a
4752      masked_array(data=[10000000000.0, 1e-07, --],
4753                   mask=[False, False,  True],
4754             fill_value=1e+20)
4755      >>> b = np.ma.array([1e10, 1e-8, -42.0], mask=[0, 0, 1])
4756      >>> np.ma.allclose(a, b)
4757      False
4758  
4759      >>> a = np.ma.array([1e10, 1e-8, 42.0], mask=[0, 0, 1])
4760      >>> b = np.ma.array([1.00001e10, 1e-9, -42.0], mask=[0, 0, 1])
4761      >>> np.ma.allclose(a, b)
4762      True
4763      >>> np.ma.allclose(a, b, masked_equal=False)
4764      False
4765  
4766      Masked values are not compared directly.
4767  
4768      >>> a = np.ma.array([1e10, 1e-8, 42.0], mask=[0, 0, 1])
4769      >>> b = np.ma.array([1.00001e10, 1e-9, 42.0], mask=[0, 0, 1])
4770      >>> np.ma.allclose(a, b)
4771      True
4772      >>> np.ma.allclose(a, b, masked_equal=False)
4773      False
4774  
4775      Fr�r�r�)r	r<)r<rQ)
rwr	rr��result_typerurX�isinfrMrr rjr)r;r�rxr�r�rdrqr	r�Zxinfr�r�r�r�r�s.H
4776  
4777  �
4778  
4779  
4780  �
4781  rcCs|pd}t||ddd|d�S)a�
4782      Convert the input to a masked array of the given data-type.
4783  
4784      No copy is performed if the input is already an `ndarray`. If `a` is
4785      a subclass of `MaskedArray`, a base class `MaskedArray` is returned.
4786  
4787      Parameters
4788      ----------
4789      a : array_like
4790          Input data, in any form that can be converted to a masked array. This
4791          includes lists, lists of tuples, tuples, tuples of tuples, tuples
4792          of lists, ndarrays and masked arrays.
4793      dtype : dtype, optional
4794          By default, the data-type is inferred from the input data.
4795      order : {'C', 'F'}, optional
4796          Whether to use row-major ('C') or column-major ('FORTRAN') memory
4797          representation.  Default is 'C'.
4798  
4799      Returns
4800      -------
4801      out : MaskedArray
4802          Masked array interpretation of `a`.
4803  
4804      See Also
4805      --------
4806      asanyarray : Similar to `asarray`, but conserves subclasses.
4807  
4808      Examples
4809      --------
4810      >>> x = np.arange(10.).reshape(2, 5)
4811      >>> x
4812      array([[0., 1., 2., 3., 4.],
4813             [5., 6., 7., 8., 9.]])
4814      >>> np.ma.asarray(x)
4815      masked_array(
4816        data=[[0., 1., 2., 3., 4.],
4817              [5., 6., 7., 8., 9.]],
4818        mask=False,
4819        fill_value=1e+20)
4820      >>> type(np.ma.asarray(x))
4821      <class 'numpy.ma.core.MaskedArray'>
4822  
4823      r>FT)r	r<r2rLr$�rw)r;r	r$r�r�r�r/Ys,
4824  �r/cCs2t|t�r|dus||jkr|St||dddd�S)ae
4825      Convert the input to a masked array, conserving subclasses.
4826  
4827      If `a` is a subclass of `MaskedArray`, its class is conserved.
4828      No copy is performed if the input is already an `ndarray`.
4829  
4830      Parameters
4831      ----------
4832      a : array_like
4833          Input data, in any form that can be converted to an array.
4834      dtype : dtype, optional
4835          By default, the data-type is inferred from the input data.
4836      order : {'C', 'F'}, optional
4837          Whether to use row-major ('C') or column-major ('FORTRAN') memory
4838          representation.  Default is 'C'.
4839  
4840      Returns
4841      -------
4842      out : MaskedArray
4843          MaskedArray interpretation of `a`.
4844  
4845      See Also
4846      --------
4847      asarray : Similar to `asanyarray`, but does not conserve subclass.
4848  
4849      Examples
4850      --------
4851      >>> x = np.arange(10.).reshape(2, 5)
4852      >>> x
4853      array([[0., 1., 2., 3., 4.],
4854             [5., 6., 7., 8., 9.]])
4855      >>> np.ma.asanyarray(x)
4856      masked_array(
4857        data=[[0., 1., 2., 3., 4.],
4858              [5., 6., 7., 8., 9.]],
4859        mask=False,
4860        fill_value=1e+20)
4861      >>> type(np.ma.asanyarray(x))
4862      <class 'numpy.ma.core.MaskedArray'>
4863  
4864      NFT)r	r<r2rL)rrr	rw)r;r	r�r�r�r.�s,r.r�cCrf)Nz1fromfile() not yet implemented for a MaskedArray.rg)�filer	r@r,r�r�r��fromfile�s�r�cCst|d|dd�S)a�
4865      Build a masked array from a suitable flexible-type array.
4866  
4867      The input array has to have a data-type with ``_data`` and ``_mask``
4868      fields. This type of array is output by `MaskedArray.toflex`.
4869  
4870      Parameters
4871      ----------
4872      fxarray : ndarray
4873          The structured input array, containing ``_data`` and ``_mask``
4874          fields. If present, other fields are discarded.
4875  
4876      Returns
4877      -------
4878      result : MaskedArray
4879          The constructed masked array.
4880  
4881      See Also
4882      --------
4883      MaskedArray.toflex : Build a flexible-type array from a masked array.
4884  
4885      Examples
4886      --------
4887      >>> x = np.ma.array(np.arange(9).reshape(3, 3), mask=[0] + [1, 0] * 4)
4888      >>> rec = x.toflex()
4889      >>> rec
4890      array([[(0, False), (1,  True), (2, False)],
4891             [(3,  True), (4, False), (5,  True)],
4892             [(6, False), (7,  True), (8, False)]],
4893            dtype=[('_data', '<i8'), ('_mask', '?')])
4894      >>> x2 = np.ma.fromflex(rec)
4895      >>> x2
4896      masked_array(
4897        data=[[0, --, 2],
4898              [--, 4, --],
4899              [6, --, 8]],
4900        mask=[[False,  True, False],
4901              [ True, False,  True],
4902              [False,  True, False]],
4903        fill_value=999999)
4904  
4905      Extra fields can be present in the structured array but are discarded:
4906  
4907      >>> dt = [('_data', '<i4'), ('_mask', '|b1'), ('field3', '<f4')]
4908      >>> rec2 = np.zeros((2, 2), dtype=dt)
4909      >>> rec2
4910      array([[(0, False, 0.), (0, False, 0.)],
4911             [(0, False, 0.), (0, False, 0.)]],
4912            dtype=[('_data', '<i4'), ('_mask', '?'), ('field3', '<f4')])
4913      >>> y = np.ma.fromflex(rec2)
4914      >>> y
4915      masked_array(
4916        data=[[0, 0],
4917              [0, 0]],
4918        mask=[[False, False],
4919              [False, False]],
4920        fill_value=999999,
4921        dtype=int32)
4922  
4923      rMrSr�r�)Zfxarrayr�r�r�rU�s=rUc@s6eZdZdZdZddd�Zdd�Zdd�Zd	d
4924  �ZdS)�_convert2maz�
4925      Convert functions from numpy to numpy.ma.
4926  
4927      Parameters
4928      ----------
4929          _methodname : string
4930              Name of the method to transform.
4931  
4932      NcCs(tt|�|_|�||�|_|pi|_dSr)r�r��_funcrlr��_extras)r\r�np_ret�	np_ma_retr
r�r�r�r] sz_convert2ma.__init__cCsJt|jdd�}t|j�}|r#|�|||�}|rd|jj|f}||}|S)ror�Nz%s%s
4933  )r�r�r��_replace_return_typer�)r\r�r�rrr�r�r�r�rl s
4934  z_convert2ma.getdoccCsD||vrtd|�d|�d|�d|jj�d|jj�d���|�||�S)a
4935          Replace documentation of ``np`` function's return type.
4936  
4937          Replaces it with the proper type for the ``np.ma`` function.
4938  
4939          Parameters
4940          ----------
4941          doc : str
4942              The documentation of the ``np`` method.
4943          np_ret : str
4944              The return type string of the ``np`` method that we want to
4945              replace. (e.g. "out : ndarray")
4946          np_ma_ret : str
4947              The return type string of the ``np.ma`` method.
4948              (e.g. "out : MaskedArray")
4949          zFailed to replace `z` with `z-`. The documentation string for return type, z(, is not found in the docstring for `np.z`. Fix the docstring for `np.z0` or update the expected string for return type.)rUr�r��replace)r\rrr�r�r�r�r�r�# s����z _convert2ma._replace_return_typecOsx|j}t|��|�}|D]	}|�|�||<q|jj|i|���t�}d|vr-|�dd�|_	d|vr:t
4950  |�dd��|_|S)Nr6rr3F)r��set�intersection�popr�rerOrrr6r�r)r\r�r
r�Z
common_params�pr<r�r�r�re? sz_convert2ma.__call__r)r�r�r�r�r]rlr�rer�r�r�r�r� s	
4951  r�r")r6rzarange : ndarrayzarange : MaskedArray)r
r�r�r5zclipped_array : ndarrayzclipped_array : MaskedArrayrFzdiff : ndarrayzdiff : MaskedArrayrHz
out : ndarrayzout : MaskedArrayrI)r�r�rTzout: MaskedArrayrVzfromfunction : anyzfromfunction: MaskedArrayr^r`z'grid : one ndarray or tuple of ndarraysz/grid : one MaskedArray or tuple of MaskedArraysr�r�r�zsqueezed : ndarrayzsqueezed : MaskedArrayr�r�cCst||g|�S)aAppend values to the end of an array.
4952  
4953      .. versionadded:: 1.9.0
4954  
4955      Parameters
4956      ----------
4957      a : array_like
4958          Values are appended to a copy of this array.
4959      b : array_like
4960          These values are appended to a copy of `a`.  It must be of the
4961          correct shape (the same shape as `a`, excluding `axis`).  If `axis`
4962          is not specified, `b` can be any shape and will be flattened
4963          before use.
4964      axis : int, optional
4965          The axis along which `v` are appended.  If `axis` is not given,
4966          both `a` and `b` are flattened before use.
4967  
4968      Returns
4969      -------
4970      append : MaskedArray
4971          A copy of `a` with `b` appended to `axis`.  Note that `append`
4972          does not occur in-place: a new array is allocated and filled.  If
4973          `axis` is None, the result is a flattened array.
4974  
4975      See Also
4976      --------
4977      numpy.append : Equivalent function in the top-level NumPy module.
4978  
4979      Examples
4980      --------
4981      >>> import numpy.ma as ma
4982      >>> a = ma.masked_values([1, 2, 3], 2)
4983      >>> b = ma.masked_values([[4, 5, 6], [7, 8, 9]], 7)
4984      >>> ma.append(a, b)
4985      masked_array(data=[1, --, 3, 4, 5, 6, --, 8, 9],
4986                   mask=[False,  True, False, False, False, False,  True, False,
4987                         False],
4988             fill_value=999999)
4989      )r9)r;r�r�r�r�r�r!� s(r!r)T)FT)TT)r�r�TTrIrHr�rGrF)Nr�r�)FN)r�T)rT)Tr�r�rE(r�rVr�r�r��textwrapr��	functoolsr�numpyr��numpy.core.umathr�rb�numpy.core.numerictypes�numerictypesr	�
4990  numpy.corerrrrrrrr	r
4991  rs�numpy.lib.function_baser�numpy.compatrr
rrrr�numpy.core.numericr�__all__rr�r]r�r�r�r�r�rrrrB�
4992  datetime64�timedelta64�half�single�double�
4993  longdouble�csingle�cdouble�clongdouble�float_types_list�_minvalsr'r<�_maxvalsr%rrrCr#r�r�r*r9r�r=r6rMrJrW�get_datarNrXr�r�rZrgrmrsrzr{r�r�r�rKr:r�r>r'r&r�r?r�rrrLr�rQr3r�r-ror�rkrmrlr�r%r#r$r)rr�r�r(rJr�rjr[rirZrnrrpr�rqr0r1r2r]rGr�rRr�rSr�r�r�rsrX�get_maskrYrer�rrrtr�rurOr�r�ryrzr}r~rrxr{r�r�r�r|r�r�r�r@�dedentr�r�rPrrrr>r�rdrgrcrErvr�rwrfrdr�r�r�rkrrrr r7rArBr<rEr\r_r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r@r�r�r+r*r,r�r8r9rDrhr�r�r�r�r�r�r�r�r�r�r4r�r�rrarbr�r�r�r=r;rrr/r.rqr�rUr�r"r5rFrHrIrTrVr^r`r�r�r�r�r�r!r�r�r�r��<module>s, $��
4994  733 ,A
 93:
4995  
4996  J
4997  L
4998  
4999  
5000  
5001  
5002  
5003  
5004  
5005  
5006  
5007  
5008  
5009  
5010  
5011  ���������
5012  
5013  
5014  
5015  
5016  
5017  
5018  
5019  
5020  
5021  
5022  
5023  
5024  
5025  
5026  ��� !;5D
5027  Y2
5028  88z ((DH(0�"7-l/
5029  
3
5030  t
5031  �:C
5032  
5033  
5034  
5035  
5036  	)M
5037  
<'&@
5038  
5039  
5040  [K5\R�
�:l16@J
5041  �
5042  �
5043  �
5044  �
5045  �
5046  �
5047  �
5048  �
5049  �
5050  �
5051  �
5052  �
5053  �
5054  �