Файловый менеджер - Редактировать - /home/digitalm/venv/lib/python3.7/site-packages/numpy/ma/__pycache__/extras.cpython-37.pyc
Назад
B �5�g�� � - @ s� d Z ddddddddd d ddd ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-g-Zd.d/lZd.d/lZd0d1lmZ d0d2lmZmZm Z m Z mZmZm Z mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ d.d/lZd.d3lmZm Z d.d/l!m m"Z" d.d4l#m$Z$ d.d5l%m&Z& d.d6l'm(Z( d.d7l)m*Z* d8d9� Z+dsd:d�Z,e-fd;d�Z.d<d � Z/G d=d>� d>�Z0G d?d@� d@e0�Z1G dAdB� dBe0�Z2G dCdD� dDe0�Z3G dEdF� dFe0�Z4e4d�Z5e4d�Z6e4d�Z7e2d-� Z8Z9e2d�Z:e2d �Z;e2d�Z<e2d)�Z=e1d�Z>e1d�Z?dGdH� Z@dId� ZAejAj eA_ dJd� ZBeBj d/k �rRejBj d/ejBj �CdK�� �D� dL eB_ dtdNd�ZEdudOd!�ZFdvdPdQ�ZGdwdRd�ZHdxdSd�ZIdTd � ZJdUd � ZKejLfdVd�ZMejLfdWd�ZNdydXd�ZOdzdYd*�ZPd{dZd�ZQd|d[d(�ZRd}d\d�ZSd~d]d�ZTd^d+� ZUdd_d'�ZVd�dadb�ZWd�dcd�ZXd/d`ejLd`ejLfddd�ZYG dedf� dfe*�ZZG dgdh� dheZ�Z[e[� Z\did� Z]d�djd$�Z^dkd� Z_d�dld#�Z`dmdn� Zadod� Zbdpd� Zcd�dqd,�Zde�eejdj edj �ed_ d�drd%�Zfe�eejfj efj �ef_ d/S )�z� 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 �E/home/digitalm-up/venv/lib/python3.7/site-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 2c 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 /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') )rY ) rV Z empty_like�viewr1 r@ rX r; rY �_mask)rR rZ rN rN rO r � s 2c @ 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�}|rH| 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 Nr` z@The function is applied to both the _data and the _mask, if any.z )�getattrrV r^ �maZget_object_signature�doc_note�join)ra Znpfunc�doc�sigrN rN rO r_ � s z_fromnxfunction.getdocc O s d S )NrN )ra �args�paramsrN rN rO �__call__ s z_fromnxfunction.__call__N)r^ � __module__�__qualname__r` rc r_ rl rN rN rN rO r] � s r] c @ s 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�rJ||�� f|�|�}|t|�f|�|�}t||d�S |t�|�f|�|�}|t|�f|�|�}t||d�S d S )N)rU ) rd rV r^ rJ rE Z __array__r: r= r5 )ra �xrj rk �func�_d�_mrN rN rO rl s z_fromnxfunction_single.__call__N)r^ rm rn r` rl rN rN rN rO ro s ro c @ s e Zd ZdZdd� ZdS )�_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 sT t t| j�}|tdd� |D ��f|�|�}|tdd� |D ��f|�|�}t||d�S )Nc S s g | ]}t �|��qS rN )rV r5 )�.0rZ rN rN rO � <listcomp># s z0_fromnxfunction_seq.__call__.<locals>.<listcomp>c S s g | ]}t |��qS rN )r: )ru rZ rN rN rO rv $ s )rU )rd rV r^ rK r= )ra rp rj rk rq rr rs rN rN rO rl ! s z_fromnxfunction_seq.__call__N)r^ rm rn r` rl rN rN rN rO rt s rt c @ s e Zd ZdZdd� ZdS )�_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|�}x,t|�dkrDt|d �rD|�|�d�� qW g }xH|D ]@}|t�|�f|�|�}|t |�f|�|�}|�t ||d�� qPW t|�dkr�|d S |S )Nr. )rU r/ )rd rV r^ rL �lenrP �append�popr5 r: r= ) ra rj rk rq �arrays�resrp rr rs rN rN rO rl 1 s z_fromnxfunction_args.__call__N)r^ rm rn r` rl rN rN rN rO rw ( s rw c @ s e Zd ZdZdd� ZdS )�_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 sj t t| j�}g }x@|D ]8}|t�|�f|�}|t|�f|�}|�t||d�� qW t|�dkrf|d S |S )N)rU r/ r. )rd rV r^ r5 r: ry r= rx )ra rj rk rq r| rp rr rs rN rN rO rl L s z _fromnxfunction_allargs.__call__N)r^ rm rn r` rl rN rN rN rO r} A s r} c C sJ d}x@|t | �krDx&t| | d�r8| | | ||d �<