%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/
Upload File :
Create Path :
Current File : //opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyo

�
�9Zc
@`sdZddlmZmZmZddlZddlZddlZddl	j
jZddl
mZddlmZmZmZmZmZddlmZmZej
jjZejZddljZddlmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&ej
j'Z'dd	d
ddd
gZ(ddddgZ)d�Z*e+d�Z,d�Z-de e.fd��YZ/d�Z0e/Z1e+e+e+e+e+e2e+e+d�Ze+e+e+e+e+e2e+e+e"d�	Zd�Z3d�Z4e+dde+e+d�Z5e+d�Z6dS(s,:mod:`numpy.ma..mrecords`

Defines the equivalent of :class:`numpy.recarrays` for masked arrays,
where fields can be accessed as attributes.
Note that :class:`numpy.ma.MaskedArray` already supports structured datatypes
and the masking of individual fields.

.. moduleauthor:: Pierre Gerard-Marchant

i(tdivisiontabsolute_importtprint_functionN(t
basestring(tbool_tdtypetndarraytrecarraytarray(t
fromarraystfromrecords(tMAErrortMaskedArraytmaskedtnomasktmasked_arraytgetdatatgetmaskarraytfilledt
MaskedRecordst	mrecarrayR	R
tfromtextfiletaddfieldt_datat_maskt
_fieldmaskRcC`s�t|d�r9djg|jjD]}|d^q"�Sd}xi|D]a}tj|�}|t|jj7}t|jjt	j
�r�|t|j�7}n|d7}qFW|d S(sR
    Returns the formats of arrays in arraylist as a comma-separated string.

    Rt,iti����(
thasattrtjoinRtdescrtnptasarrayt_typestrttypet
issubclasstntypestflexibletreprtitemsize(tdatatdesctformatstobj((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyt_getformats3s*
c
C`s[t|�}gt|�D]}d|^q}|dkrD|}n~t|ttf�rb|}n7t|t�r�|jd�}ntdt	|���t|�}||kr�|||7}ng}x�t
|||j�D]l\}}}	|tkr3|	dtkr#|j
||	df�qJ|j
|	�q�|j
||	df�q�Wtj|�S(s�
    Checks that field names ``descr`` are not reserved keywords.

    If this is the case, a default 'f%i' is substituted.  If the argument
    `names` is not None, updates the field names to valid names.

    sf%iRsillegal input names %siiN(tlentrangetNonet
isinstancettupletlisttstrtsplitt	NameErrorR&tzipRtreserved_fieldstappendRR(
Rtnamestndescrtit
default_namest	new_namestnnamestntdtt((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyt_checknamesEs(#		%cC`s]g|jjD]}|df^q
}tj|jd|�}ttgt|��|_|S(Ns|b1R(	RR9RtemptytshapeR1tFalseR-tflat(tselfR?tmdescrtfdmask((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyt_get_fieldmaskgs%cB`s
eZdZddddddddeeedeed�Zd�Zd�Z	e
de	�Zd�Ze
de�Z
d�Zd�Zd	�Zd
�Zd�Zd�Zd
�Zddd�Zd�Zd�Zd�Zdd�Zd�Zd�Zd�ZRS(s�

    Attributes
    ----------
    _data : recarray
        Underlying data, as a record array.
    _mask : boolean array
        Mask of the records. A record is masked when all its fields are
        masked.
    _fieldmask : boolean recarray
        Record array of booleans, setting the mask of each individual field
        of each record.
    _fill_value : record
        Filling values for each field.

    icK`s�tj||d|d|d|d|d|d|d|d|	d	|
�	}tj|j�}|tksvtj|�r�|s�tt	gt
|��|_q�n&tj|d
|�}|j
|j
krI|j|j}}|dkr�tj||j
�}nD||kr tj||j
�}n dd
}t|||f��t}n|sh|j|�t|_n\|j|kr�|}n;tjg|D]}t|gt
|��^q�d|�}||_|S(NRtbuftoffsettstridesR*R9ttitlest	byteordertalignedtcopyis/Mask and data not compatible: data size is %i, smask size is %i.(Rt__new__tmatmake_mask_descrRRRtsizeR1RER-RRRDtresizetreshapeRtTruet__setmask__t_sharedmask(tclsRDRRKRLRMR*R9RNRORPtmaskt	hard_maskt
fill_valuet	keep_maskRQtoptionsRGtmdtypetndtnmtmsgRtm((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyRR�s8!	"	
	2		cC`st|dd�}|dkr�t|dt�}tj|d�}|tkritj|jd|�}q�tj|�}t	g|D]}t
|gt|��^q�d|�jt
�}n|j}|jd|�|j|�|dtkr�t
|d<ndS(NRRt
_baseclass(tgetattrR/RRt__getattribute__RStmake_mask_noneRDRTtnarrayR1R-tviewRt__dict__tupdatet_update_from(RGR+Rtobjmaskt_dtypeRHRet_dict((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyt__array_finalize__�s/	

cC`stj|t�S(s2
        Returns the data as a recarray.

        (RRkR(RG((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyt_getdata�stfgetcC`s|jS(s!
        Alias to mask.

        (R(RG((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyt
_getfieldmask�scC`s#|jrt|j�St|j�S(s%
        Returns the length

        (tndimR-RR(RG((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyt__len__�s	
c
C`s�ytj||�SWntk
r'nXtj|d�j}y||d }Wn'ttfk
rxtd|��nXtj|d�}tj||d�}|j|�}|j	jr�t
d��nt}|jdd�}|dk	rAy||}Wntk
rnX|jtjt|j	�p/df�j�}n|jsP|r�|jt�}t|_t|_||_|jd	d�}	|	dk	r�y|	||_Wq�tk
r�d|_q�Xq�n|j�}|S(
NRis record array has no attribute %sRlRfs4MaskedRecords is currently limited tosimple records.Rit_fill_value(tobjectRhtAttributeErrorRtfieldst	TypeErrortKeyErrorRktgetfieldRtNotImplementedErrorREtgetR/t
IndexErrorRtboolR-tanyRDRRfRXt_isfieldRRxt
ValueErrortitem(
RGtattrt	fielddicttrest
_localdictRR+t	hasmaskedRRx((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyRh�sF

0			
cC`s�|dkr|j|�dStj|d�}||k}ytj|||�}Wnwtj|d�jpri}tj|d�p�i}||kp�||ks!tj�d \}}	||	��q!nTXtj|d�jp�i}||kr�|S|r!ytj||�Wq!|SXny||d }
Wn't	t
fk
r\td|��nX|tkr�|d	}|dk	r�|d	|}n|}t}
nt|�}t|�}
tj|d
�j||
�}|dj||
�|S(
s<
        Sets the attribute attr to the value val.

        R\t	fieldmaskNRlRt_optinfois record array has no attribute %sRxRR(R\R�(RYRyRht__setattr__RR{tsystexc_infot__delattr__R|R}RzR
R/RXRRtsetfieldt__setitem__(RGR�tvalR�tnewattrtretR�toptinfotexctypetvalueR�RxtdvaltmvalR+((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyR�sH

	cC`s�|j}tj|d�}tj||d�}t|t�r�||jt�}|||_t|_	|d}|dk	r�|||_n|jr�|jr�t
S|Stj||dt�jt�}tj||dt�jt�|_|S(s�
        Returns all the fields sharing the same fieldname base.

        The fieldname base is either `_data` or `_mask`.

        RRfRxRQN(RlRRhRkR0RRRRXRZR/RxRvR
RRRERR(RGtindxR�RRR+tfval((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyt__getitem__?s 	
	
"%cC`s?tj|||�t|t�r;tj|�|j|<ndS(s2
        Sets the given record to value.

        N(RR�R0RRSRR(RGR�R�((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyR�_scC`s|jdkr�gtg|jjD]}t||�^q"�D]2}ddjg|D]}t|�^qT�^q>}ddj|�Sgtg|jjD]}t||�^q��D]2}ddjg|D]}t|�^q��^q�}ddj|�SdS(s8
        Calculates the string representation.

        is(%s)Rs[%s]s, s%sN(RUR6RR9RgRR3(RGtftsR;tmstr((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyt__str__hsddcC`s�|jj}dtg|D]}t|�^q�df}g|jjD]}||t||�f^qI}|jdd�|j|d|jfdg�tdj	|��S(s6
        Calculates the repr representation.

        s%%%is : %%siismasked_records(s    fill_values              )s
(
RR9tmaxR-RgtinserttextendR^R3R(RGt_namesR?tfmtR�treprstr((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyt__repr__vs02
cC`s�|dkr?|dkr*tj|�}q(tj||�}n�|dkry@t|t�rxtj||�}d}ntj||�}Wq(tk
rtj|�}|jdkr�|jj	d}|j
�j||�}|j|�ntj||�}d|_q(Xntj|||�}t
|dt�tk	r|tj|j�}|jj|t�|_|j|j_n|S(s3
        Returns a view of the mrecarray.

        iRN(R/RRkR#R|RRR{t	__class__t	__bases__t	__array__RnRxRgRRSRTRRD(RGRR"toutputtbasetypeRa((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyRk�s0	
cC`s
t|_dS(s+
        Forces the mask to hard.

        N(RXt	_hardmask(RG((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pytharden_mask�scC`s
t|_dS(s*
        Forces the mask to soft

        N(RER�(RG((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pytsoften_mask�scC`s4|jj�jt|��}|jj�|_|S(s7
        Returns a copy of the masked record.

        (RRQRkR"R(RGtcopied((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyRQ�scC`sf|dk	r|j|�j�St|j�j�dt�}t|jj��}d||<|j�S(s
        Return the data portion of the array as a list.

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

        RN(R/RttolistRjRyR(RGR^tresultR\((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyR��s	
cC`s@d|j|j|jj|jj�|jj�|jf}|S(sWReturn the internal state of the masked array.

        This is for pickling.

        i(RDRtflagstfncRttobytesRRx(RGtstate((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyt__getstate__�s	cC`s�|\}}}}}}}tj|||||f�tg|jjD]\}	}
|	tf^qG�}|jdj||||f�||_dS(st
        Restore the internal state of the masked array.

        This is for pickling.  ``state`` is typically the output of the
        ``__getstate__`` output, and is a 5-tuple:

        - class name
        - a tuple giving the shape of the data
        - a typecode for the data
        - a binary string for the data
        - a binary string for the mask.

        RN(Rt__setstate__RRRRlR^(RGR�tvertshpttyptisftrawtmsktflvtkt_Ra((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyR��s
1 cC`s%t|j|jddf|j�fS(s?
        Return a 3-tuple for pickling a MaskedArray.

        itb(i(t_mrreconstructR�RfR�(RG((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyt
__reduce__�sN(t__name__t
__module__t__doc__R/RERRXRRRrRstpropertyRRuRRwRhR�R�R�R�R�RkR�R�RQR�R�R�R�(((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyRns4	%					-	8	 				
)						cC`sOtj|||�j|�}tjt|d�}|j||d|d|�S(sK
    Build a new MaskedArray from the information stored in a pickle.

    tb1R\R(RRRRk(tsubtypet	baseclasst	baseshapeR�RR((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyR�sc	
C`s�g|D]}	t|	�^q}
g|D]}	tjt|	��^q&}t|
d|d|d|d|d|d|d|�jt�}tt|��|j	_
|dk	r�||_n|S(	s

    Creates a mrecarray from a (flat) list of masked arrays.

    Parameters
    ----------
    arraylist : sequence
        A list of (masked) arrays. Each element of the sequence is first converted
        to a masked array if needed. If a 2D array is passed as argument, it is
        processed line by line
    dtype : {None, dtype}, optional
        Data type descriptor.
    shape : {None, integer}, optional
        Number of records. If None, shape is defined from the shape of the
        first array in the list.
    formats : {None, sequence}, optional
        Sequence of formats for each individual field. If None, the formats will
        be autodetected by inspecting the fields and selecting the highest dtype
        possible.
    names : {None, sequence}, optional
        Sequence of the names of each field.
    fill_value : {None, sequence}, optional
        Sequence of data to be used as filling values.

    Notes
    -----
    Lists of tuples should be preferred over lists of lists for faster processing.

    RRDR*R9RNRPRON(
RRt
atleast_1dRt
recfromarraysRkRR2R6RRFR/R^(
t	arraylistRRDR*R9RNRPROR^txtdatalisttmasklistt_array((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyR	s(	c
C`sut|dd�}
t|t�rot|t�rH|j�jt�}n|dkr`|j}n|j�}nt	|d|d|d|d|d|d|d|�jt
�}|dk	r�||_n|	tk	rXt
j|	d	t�}	t|	j�}|r|	|j_qXt|	j�d
krHg|	D]}
t|
�^q'|j_qX|j|	�n|
dk	rq|
|j(n|S(sN
    Creates a MaskedRecords from a list of records.

    Parameters
    ----------
    reclist : sequence
        A list of records. Each element of the sequence is first converted
        to a masked array if needed. If a 2D array is passed as argument, it is
        processed line by line
    dtype : {None, dtype}, optional
        Data type descriptor.
    shape : {None,int}, optional
        Number of records. If None, ``shape`` is defined from the shape of the
        first array in the list.
    formats : {None, sequence}, optional
        Sequence of formats for each individual field. If None, the formats will
        be autodetected by inspecting the fields and selecting the highest dtype
        possible.
    names : {None, sequence}, optional
        Sequence of the names of each field.
    fill_value : {None, sequence}, optional
        Sequence of data to be used as filling values.
    mask : {nomask, sequence}, optional.
        External mask to apply on the data.

    Notes
    -----
    Lists of tuples should be preferred over lists of lists for faster processing.

    RRRDR*R9RNRPRORQiN(RgR/R0RRRRkRR�trecfromrecordsRR^RRRRER-RRFRDR1RY(treclistRRDR*R9RNRPROR^R\RtmrectmaskrecordlengthRe((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyR
<s."(
cC`s(g}tj|�}t|j�dkr7|d}n$t|j�dkr[td��nx�|D]�}yt|�Wn�tk
r	yt|�WnYtk
r�yt|�Wn!tk
r�|j|j	�qX|jtj	t��q X|jtj	t��qbX|jtj	t��qbW|S(s.
    Tries to guess the dtypes of the str_ ndarray `arr`.

    Guesses by testing element-wise conversion. Returns a list of dtypes.
    The array is first converted to ndarray. If the array is 2D, the test
    is performed on the first line. An exception is raised if the file is
    3D or more.

    iisThe array should be 2D at most!(
RR R-RDR�tinttfloattcomplexR8R(tarrtvartypesR�((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyt_guessvartypes}s*





cC`s�t|d�r|Syt|�}Wn!tk
rFtd|��nX|j�d dkrq|jdd�|S|j�td��dS(s1
    Opens the file handle of file `fname`.

    treadlinesNo such file: '%s'is\xisWow, binary fileN(RtopentIOErrorR�tseektcloseR(tfnameR�((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pytopenfile�s

t#Rc
C`s2t|�}xTtrb|j�}||j|� j�}|j|�}	t|	�dkrPqqW|dkrx|	}ntg|D]=}|d|kr�t|�dkr�|j�j|�^q��}
|
j	\}}|j
�|dkrt|
d�}ntg|D]}
tj
|
�^q}t|�|krtd}|d7}tj|t|�|f�t|
d�}ngt||�D]\}}||f^q�}g|D]}tj|�^q�}|
j|k}gt|
j|||�D]0\}}}}t|d|d|d|�^q�}t|d|�S(	s�
    Creates a mrecarray from data stored in the file `filename`.

    Parameters
    ----------
    fname : {file name/handle}
        Handle of an opened file.
    delimitor : {None, string}, optional
        Alphanumeric character used to separate columns in the file.
        If None, any (group of) white spacestring(s) will be used.
    commentchar : {'#', string}, optional
        Alphanumeric character used to mark the start of a comment.
    missingchar : {'', string}, optional
        String indicating missing data, and used to create the masks.
    varnames : {None, sequence}, optional
        Sequence of the variable names. If None, a list will be created from
        the first non empty line of the file.
    vartypes : {None, sequence}, optional
        Sequence of the variables dtypes. If None, it will be estimated from
        the first non-commented line.


    Ultra simple: the varnames are in the header, one lineiis&Attempting to %i dtypes for %i fields!s Reverting to default.R\RR^N(R�RXR�tfindtstripR4R-R/RRDR�R�RRtwarningstwarnR6RStdefault_fill_valuetTR	(R�t	delimitortcommentchartmissingchartvarnamesR�tftexttlinet	firstlinet	_varnamest
_variablesR�tnfieldstvRdR?R�RHtmfillvRtaReRAt	_datalist((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyR�s6		@
"
."LcC`s�|j}|j}|dks*|tkr@dt|j�}ntj|�}tj|jj	||jfg�}t
|j|�}g|jjj
�D]!}|j|j|�|�^q�|j|j|jj|�|jt�}tjg|jD]}|tf^q��}	t
|j|	�}
g|jjj
�D]!}|
j|j|�|�^q:|
jt|�|
jj|�|
|_|S(s�Adds a new field to the masked record array

    Uses `newfield` as data and `newfieldname` as name. If `newfieldname`
    is None, the new field name is set to 'fi', where `i` is the number of
    existing fields.

    sf%iN(RRR/R7R-RRSRRRRRDR{tvaluesR�R~RkRR9RR(tmrecordtnewfieldtnewfieldnameRRtnewdtypetnewdataR�R?t	newmdtypetnewmask((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyR�s&		%5+5	(7R�t
__future__RRRR�R�tnumpyRtnumpy.core.numerictypestcoretnumerictypesR$tnumpy.compatRRRRRRRjtnumpy.core.recordsR	R�R
R�trecordst_byteorderconvR!tnumpy.maRSRRR
RRRRRt_check_fill_valuet__all__R7R,R/RBRJRyRR�RRER�R�RR(((sD/opt/alt/python27/lib64/python2.7/site-packages/numpy/ma/mrecords.pyt<module>
sD(	:	"	��			)	?	%		C

Zerion Mini Shell 1.0