File: //usr/lib/python3/dist-packages/numpy/ma/__pycache__/extras.cpython-310.pyc
o
6��a�� � @ st d Z g d�ZddlZddlZddlmZ ddlmZmZm Z m
Z
mZmZm
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddlZddlmZm
Z ddl!m m"Z" ddl#m$Z$ dd l%m&Z& dd
l'm(Z( ddl)m*Z* dd
� Z+dpdd�Z,e-fdd�Z.dd� Z/G dd� d�Z0G dd� de0�Z1G dd� de0�Z2G dd� de0�Z3G dd� de0�Z4e4d�Z5e4d�Z6e4d �Z7e2d!� Z8Z9e2d"�Z:e2d#�Z;e2d$�Z<e2d%�Z=e1d&�Z>e1d'�Z?d(d)� Z@d*d+� ZAejAj eA_ d,d-� ZBeBj dur�ejBj dejBj �Cd.�� �D� d/ eB_ dqd1d2�ZEdrd3d4�ZFdqd5d6�ZGdpd7d8�ZHdpd9d:�ZId;d<� ZJd=d>� ZKejLfd?d@�ZMejLfdAdB�ZNdsdCdD�ZOdtdEdF�ZPdudGdH�ZQdudIdJ�ZRdtdKdL�ZSdtdMdN�ZTdOdP� ZUdudQdR�ZVdvdTdU�ZWdwdVdW�ZXddSejLdSejLfdXdY�ZYG dZd[� d[e*�ZZG d\d]� d]eZ�Z[e[� Z\d^d_� Z]dpd`da�Z^dbdc� Z_dpddde�Z`dfdg� Zadhdi� Zbdjdk� Zcdpdldm�Zde�eejdj edj �ed_ dxdndo�Zfe�eejfj efj �ef_ dS )yz�
Masked arrays add-ons.
A collection of utilities for `numpy.ma`.
:author: Pierre Gerard-Marchant
:contact: pierregm_at_uga_dot_edu
:version: $Id: extras.py 3473 2007-10-29 15:18:13Z jarrod.millman $
)-�apply_along_axis�apply_over_axes�
atleast_1d�
atleast_2d�
atleast_3d�average�clump_masked�clump_unmasked�column_stack�
compress_cols�compress_nd�compress_rowcols�
compress_rows�count_masked�corrcoef�cov�diagflat�dot�dstack�ediff1d�flatnotmasked_contiguous�flatnotmasked_edges�hsplit�hstack�isin�in1d�intersect1d� mask_cols�mask_rowcols� mask_rows�
masked_all�masked_all_like�median�mr_�notmasked_contiguous�notmasked_edges�polyfit� row_stack� setdiff1d�setxor1d�stack�unique�union1d�vander�vstack� N� )�core)�MaskedArray�MAError�add�array�asarray�concatenate�filled�count�getmask�getmaskarray�make_mask_descr�masked�masked_array�mask_or�nomask�ones�sort�zeros�getdata�get_masked_subclassr r )�ndarrayr4 )�normalize_axis_index)�normalize_axis_tuple)�_ureduce)�AxisConcatenatorc C s t | tttf�S )z6
Is seq a sequence (ndarray, list or tuple)?
)�
isinstancerE �tuple�list)�seq� rN �1/usr/lib/python3/dist-packages/numpy/ma/extras.py�
issequence+ s rP c C s t | �}|�|�S )a�
Count the number of masked elements along the given axis.
Parameters
----------
arr : array_like
An array with (possibly) masked elements.
axis : int, optional
Axis along which to count. If None (default), a flattened
version of the array is used.
Returns
-------
count : int, ndarray
The total number of masked elements (axis=None) or the number
of masked elements along each slice of the given axis.
See Also
--------
MaskedArray.count : Count non-masked elements.
Examples
--------
>>> import numpy.ma as ma
>>> a = np.arange(9).reshape((3,3))
>>> a = ma.array(a)
>>> a[1, 0] = ma.masked
>>> a[1, 2] = ma.masked
>>> a[2, 1] = ma.masked
>>> a
masked_array(
data=[[0, 1, 2],
[--, 4, --],
[6, --, 8]],
mask=[[False, False, False],
[ True, False, True],
[False, True, False]],
fill_value=999999)
>>> ma.count_masked(a)
3
When the `axis` keyword is used an array is returned.
>>> ma.count_masked(a, axis=0)
array([1, 1, 1])
>>> ma.count_masked(a, axis=1)
array([0, 2, 1])
)r: �sum)�arr�axis�mrN rN rO r 3 s 2
r c C s$ t t�| |�t�| t|��d�}|S )a
Empty masked array with all elements masked.
Return an empty masked array of the given shape and dtype, where all the
data are masked.
Parameters
----------
shape : tuple
Shape of the required MaskedArray.
dtype : dtype, optional
Data type of the output.
Returns
-------
a : MaskedArray
A masked array with all data masked.
See Also
--------
masked_all_like : Empty masked array modelled on an existing array.
Examples
--------
>>> import numpy.ma as ma
>>> ma.masked_all((3, 3))
masked_array(
data=[[--, --, --],
[--, --, --],
[--, --, --]],
mask=[[ True, True, True],
[ True, True, True],
[ True, True, True]],
fill_value=1e+20,
dtype=float64)
The `dtype` parameter defines the underlying data type.
>>> a = ma.masked_all((3, 3))
>>> a.dtype
dtype('float64')
>>> a = ma.masked_all((3, 3), dtype=np.int32)
>>> a.dtype
dtype('int32')
��mask)r= �np�emptyr@ r; )�shape�dtype�arN rN rO r i s /�r c C s, t �| ��t�}t j|jt|j�d�|_|S )a�
Empty masked array with the properties of an existing array.
Return an empty masked array of the same shape and dtype as
the array `arr`, where all the data are masked.
Parameters
----------
arr : ndarray
An array describing the shape and dtype of the required MaskedArray.
Returns
-------
a : MaskedArray
A masked array with all data masked.
Raises
------
AttributeError
If `arr` doesn't have a shape attribute (i.e. not an ndarray)
See Also
--------
masked_all : Empty masked array with all elements masked.
Examples
--------
>>> import numpy.ma as ma
>>> arr = np.zeros((2, 3), dtype=np.float32)
>>> arr
array([[0., 0., 0.],
[0., 0., 0.]], dtype=float32)
>>> ma.masked_all_like(arr)
masked_array(
data=[[--, --, --],
[--, --, --]],
mask=[[ True, True, True],
[ True, True, True]],
fill_value=1e+20,
dtype=float32)
The dtype of the masked array matches the dtype of `arr`.
>>> arr.dtype
dtype('float32')
>>> ma.masked_all_like(arr).dtype
dtype('float32')
�rZ ) rW �
empty_like�viewr1 r@ rY r; rZ �_mask)rR r[ rN rN rO r � s 2r c @ s( e Zd ZdZdd� Zdd� Zdd� ZdS ) �_fromnxfunctionaV
Defines a wrapper to adapt NumPy functions to masked arrays.
An instance of `_fromnxfunction` can be called with the same parameters
as the wrapped NumPy function. The docstring of `newfunc` is adapted from
the wrapped function as well, see `getdoc`.
This class should not be used directly. Instead, one of its extensions that
provides support for a specific type of input should be used.
Parameters
----------
funcname : str
The name of the function to be adapted. The function should be
in the NumPy namespace (i.e. ``np.funcname``).
c C s || _ | �� | _d S �N)�__name__�getdoc�__doc__)�self�funcnamerN rN rO �__init__� s z_fromnxfunction.__init__c C sL t t| jd�}t |dd�}|r$| jt�|� }t�|d�}d�||f�S dS )aK
Retrieve the docstring and signature from the function.
The ``__doc__`` attribute of the function is used as the docstring for
the new masked array version of the function. A note on application
of the function to the mask is appended.
Parameters
----------
None
Nrd z@The function is applied to both the _data and the _mask, if any.z
)�getattrrW rb �ma�get_object_signature�doc_note�join)re �npfunc�doc�sigrN rN rO rc � s
z_fromnxfunction.getdocc O s d S ra rN )re �args�paramsrN rN rO �__call__ s z_fromnxfunction.__call__N)rb �
__module__�__qualname__rd rg rc rr rN rN rN rO r` � s
r` c @ � e Zd ZdZdd� ZdS )�_fromnxfunction_singlez�
A version of `_fromnxfunction` that is called with a single array
argument followed by auxiliary args that are passed verbatim for
both the data and mask calls.
c O s� t t| j�}t|t�r+||�� g|�R i |��}|t|�g|�R i |��}t||d�S |t�|�g|�R i |��}|t|�g|�R i |��}t||d�S )NrU ) rh rW rb rJ rE � __array__r: r= r5 �re �xrp rq �func�_d�_mrN rN rO rr s
z_fromnxfunction_single.__call__N�rb rs rt rd rr rN rN rN rO rv � rv c @ ru )�_fromnxfunction_seqz�
A version of `_fromnxfunction` that is called with a single sequence
of arrays followed by auxiliary args that are passed verbatim for
both the data and mask calls.
c O s` t t| j�}|tdd� |D ��g|�R i |��}|tdd� |D ��g|�R i |��}t||d�S )Nc S s g | ]}t �|��qS rN )rW r5 ��.0r[ rN rN rO �
<listcomp># s z0_fromnxfunction_seq.__call__.<locals>.<listcomp>c S s g | ]}t |��qS rN )r: r� rN rN rO r� $ s rU )rh rW rb rK r= rx rN rN rO rr ! s $$z_fromnxfunction_seq.__call__Nr} rN rN rN rO r r~ r c @ ru )�_fromnxfunction_argsa�
A version of `_fromnxfunction` that is called with multiple array
arguments. The first non-array-like input marks the beginning of the
arguments that are passed verbatim for both the data and mask calls.
Array arguments are processed independently and the results are
returned in a list. If only one array is found, the return value is
just the processed array instead of a list.
c O s� t t| j�}g }t|�}t|�dkr,t|d �r,|�|�d�� t|�dkr,t|d �sg }|D ]&}|t�|�g|�R i |��}|t |�g|�R i |��}|�t
||d�� q0t|�dkra|d S |S )Nr. rU r/ )rh rW rb rL �lenrP �append�popr5 r: r= ) re rp rq rz �arrays�resry r{ r| rN rN rO rr 1 s �z_fromnxfunction_args.__call__Nr} rN rN rN rO r� ( s r� c @ ru )�_fromnxfunction_allargsa
A version of `_fromnxfunction` that is called with multiple array
arguments. Similar to `_fromnxfunction_args` except that all args
are converted to arrays even if they are not so already. This makes
it possible to process scalars as 1-D arrays. Only keyword arguments
are passed through verbatim for the data and mask calls. Arrays
arguments are processed independently and the results are returned
in a list. If only one arg is present, the return value is just the
processed array instead of a list.
c O sn t t| j�}g }|D ] }|t�|�fi |��}|t|�fi |��}|�t||d�� q
t|�dkr5|d S |S )NrU r/ r. )rh rW rb r5 r: r� r= r� )re rp rq rz r� ry r{ r| rN rN rO rr L s z _fromnxfunction_allargs.__call__Nr} rN rN rN rO r� A s
r� r r r r- r r r r) r r c C sX d}|t | �kr*t| | d�r | | | ||d �<