Ñò \ÐKc@sødZddkZddklZlZlZddkZ ddkl Z l Z ddk i Z ddk lZddklZddklZe i iiZdd d d d d ddddddg Zd„Zd„Zd„Zd„Zed„Zddd„Zd„Zd„Zde d„Z!e ed„Z"dd„Z#dee ed„Z$e ed „Z%d!„Z&d"„Z'ddde ed#„Z(dd$„Z)de eed%„Z*de ed&„Z+d'd(d)de ed*„Z,d'd(d)dd+„Z-dS(,sÆ Collection of utilities to manipulate structured arrays. Most of these functions were initially implemented by John Hunter for matplotlib. They have been rewritten and extended for convenience. iÿÿÿÿN(tchaintrepeattizip(tndarraytrecarray(t MaskedArray(t MaskedRecords(t_is_string_liket append_fieldst drop_fieldstfind_duplicatestget_fieldstructuretjoin_byt merge_arraystrec_append_fieldstrec_drop_fieldstrec_jointrecursive_fill_fieldst rename_fieldst stack_arrayscCs~|i}xn|iD]c}y||}Wntj o qnX|iiot|||ƒq|||t|ƒ*qW|S(s* Fills fields from output with fields from input, with support for nested structures. Parameters ---------- input : ndarray Input array. output : ndarray Output array. Notes ----- * `output` should be at least the same size as `input` Examples -------- >>> a = np.array([(1, 10.), (2, 20.)], dtype=[('A', int), ('B', float)]) >>> b = np.zeros((3,), dtype=a.dtype) >>> recursive_fill_fields(a, b) np.array([(1, 10.), (2, 20.), (0, 0.)], dtype=[('A', int), ('B', float)]) (tdtypetnamest ValueErrorRtlen(tinputtoutputtnewdtypetfieldtcurrent((s</usr/lib64/python2.6/site-packages/numpy/lib/recfunctions.pyR#s   cCsug}|i}xR|D]J}||}|io#|i|tt|ƒƒfƒq|i|ƒqWt|ƒpdS(s» Returns the field names of the input datatype as a tuple. Parameters ---------- adtype : dtype Input datatype Examples -------- >>> get_names(np.empty((1,), dtype=int)) is None True >>> get_names(np.empty((1,), dtype=[('A',int), ('B', float)])) ('A', 'B') >>> adtype = np.dtype([('a', int), ('b', [('ba', int), ('bb', int)])]) >>> get_names(adtype) ('a', ('b', ('ba', 'bb'))) N(Rtappendttuplet get_namestNone(tadtypet listnamesRtnameR((s</usr/lib64/python2.6/site-packages/numpy/lib/recfunctions.pyRIs   #cCsig}|i}xF|D]>}|i|ƒ||}|io|it|ƒƒqqWt|ƒpdS(sô Returns the field names of the input datatype as a tuple. Nested structure are flattend beforehand. Parameters ---------- adtype : dtype Input datatype Examples -------- >>> get_names_flat(np.empty((1,), dtype=int)) is None True >>> get_names_flat(np.empty((1,), dtype=[('A',int), ('B', float)])) ('A', 'B') >>> adtype = np.dtype([('a', int), ('b', [('ba', int), ('bb', int)])]) >>> get_names_flat(adtype) ('a', 'b', 'ba', 'bb') N(RRtextendtget_names_flatRR (R!R"RR#R((s</usr/lib64/python2.6/site-packages/numpy/lib/recfunctions.pyR%gs    cCsŠ|i}|djo|iSg}xU|D]M}|i|\}}|io|it|ƒƒq+|i||fƒq+Wt|ƒSdS(s Flatten a structured data-type description. Examples -------- >>> ndtype = np.dtype([('a', '>> flatten_descr(ndtype) (('a', dtype('int32')), ('ba', dtype('float64')), ('bb', dtype('int32'))) N(RR tdescrtfieldsR$t flatten_descrRR(tndtypeRR&Rttypt_((s</usr/lib64/python2.6/site-packages/numpy/lib/recfunctions.pyR(…s   cCs¯g}|o+x|D]}|it|iƒƒqWnhxd|D]\}|i}|ipd}t|ƒdjo|id|ifƒq?|i|iƒq?Wti|ƒiS(sî Combine the dtype description of a series of arrays. Parameters ---------- seqarrays : sequence of arrays Sequence of arrays flatten : {boolean}, optional Whether to collapse nested descriptions. it((R$R(RRRRR&tnp(t seqarraystflattenRtaRR((s</usr/lib64/python2.6/site-packages/numpy/lib/recfunctions.pyt zip_descržs  c Cs|djo h}n|i}xÒ|D]Ê}||}|io?|o|g||>> ndtype = np.dtype([('A', int), ... ('B', [('BA', int), ... ('BB', [('BBA', int), ('BBB', int)])])]) >>> get_fieldstructure(ndtype) {'A': [], 'B': [], 'BA': ['B'], 'BB': ['B'], 'BBA': ['B', 'BB'], 'BBB': ['B', 'BB']} N(R RtupdateR tgetR( R!tlastnametparentsRR#Rt_[1]R+t lastparent((s</usr/lib64/python2.6/site-packages/numpy/lib/recfunctions.pyR ¸s$      4 ccsSxL|D]D}t|tiƒo&x(tt|ƒƒD] }|Vq3Wq|VqWdS(st Returns an iterator of concatenated fields from a sequence of arrays, collapsing any nested structure. N(t isinstanceR-tvoidt_izip_fields_flatR(titerabletelementtf((s</usr/lib64/python2.6/site-packages/numpy/lib/recfunctions.pyR:çs ccs§x |D]˜}t|dƒo1t|tƒ o xnt|ƒD] }|Vq;Wqt|tiƒo9tt|ƒƒdjo x"t|ƒD] }|Vq‡Wq|VqWdS(sO Returns an iterator of concatenated fields from a sequence of arrays. t__iter__iN(thasattrR8t basestringt _izip_fieldsR-R9RR(R;R<R=((s</usr/lib64/python2.6/site-packages/numpy/lib/recfunctions.pyRAôs!  ,  c cs¹|gt|ƒdid„}t|ƒ}g}|D]}|t||ƒ|ƒq7~}|o t}nt}y,x%t|ŒD]} t|| ƒƒVqƒWWntj onXdS(s+ Returns an iterator of concatenated items from a sequence of arrays. Parameters ---------- seqarray : sequence of arrays Sequence of arrays. fill_value : {None, integer} Value used to pad shorter iterables. flatten : {True, False}, Whether to icss |ƒVdS(s*Yields the fill_value or raises IndexErrorN((tcounter((s</usr/lib64/python2.6/site-packages/numpy/lib/recfunctions.pytsentinelsN( Rtpopt iterrepeatt iterchainR:RAtiterizipRt IndexError( R.t fill_valueR/RCtfillersR6tittiterstzipfuncttup((s</usr/lib64/python2.6/site-packages/numpy/lib/recfunctions.pyt izip_recordss  0  cCslt|tƒp t}n|o|o|itƒ}qhn*ti|ƒ}|o|itƒ}n|S(s€ Private function: return a recarray, a ndarray, a MaskedArray or a MaskedRecords depending on the input parameters (R8RtFalsetviewRtmatfilledR(Rtusemaskt asrecarray((s</usr/lib64/python2.6/site-packages/numpy/lib/recfunctions.pyt _fix_output$s cCs~|ii}|i|i|i}}}xN|phiƒD]9\}}||jo |||<|||||>> merge_arrays((np.array([1, 2]), np.array([10., 20., 30.]))) masked_array(data = [(1, 10.0) (2, 20.0) (--, 30.0)], mask = [(False, False) (False, False) (True, False)], fill_value=(999999, 1e+20) dtype=[('f0', '>> merge_arrays((np.array([1, 2]), np.array([10., 20., 30.])), ... usemask=False) array(data = [(1, 10.0) (2, 20.0) (-1, 30.0)], dtype=[('f0', '>> merge_arrays((np.array([1, 2]).view([('a', int)]), np.array([10., 20., 30.])), usemask=False, asrecarray=True) rec.array(data = [(1, 10.0) (2, 20.0) (-1, 30.0)], dtype=[('a', int), ('f1', 's RRI(i(RR8RRR1tTrueR&travelRRQRRRRRtgetdatat getmaskarrayt_check_fill_valuetmaxt enumeratetzipR-R9tonestitemtarrayRFRORtfromitertlistt_mask(R.RIR/RTRUtseqdtypeRR6R0tseqdatat_[2]tseqmaskt_[3]t maxlengthtitmtfvaltfmskt nbmissingRWRXR((s</usr/lib64/python2.6/site-packages/numpy/lib/recfunctions.pyR Cs^#    00- #  cst|ƒo |g}n t|ƒ}‡fd†‰ˆ|i|ƒ}|pdSti|id|ƒ}t||ƒ}t|d|d|ƒS(s2 Return a new array with fields in `drop_names` dropped. Nested fields are supported. Parameters ---------- base : array Input array drop_names : string or sequence String or sequence of strings corresponding to the names of the fields to drop. usemask : {False, True}, optional Whether to return a masked array or not. asrecarray : string or sequence Whether to return a recarray or a mrecarray (`asrecarray=True`) or a plain ndarray or masked array with flexible dtype (`asrecarray=False`) Examples -------- >>> a = np.array([(1, (2, 3.0)), (4, (5, 6.0))], dtype=[('a', int), ('b', [('ba', float), ('bb', int)])]) >>> drop_fields(a, 'a') array([((2.0, 3),), ((5.0, 6),)], dtype=[('b', [('ba', '>> drop_fields(a, 'ba') array([(1, (3,)), (4, (6,))], dtype=[('a', '>> drop_fields(a, ['ba', 'bb']) array([(1,), (4,)], dtype=[('a', '>> a = np.array([(1, (2, [3.0, 30.])), (4, (5, [6.0, 60.]))], dtype=[('a', int), ('b', [('ba', float), ('bb', (float, 2))])]) >>> rename_fields(a, {'a':'A', 'bb':'BB'}) array([(1, (2.0, 3)), (4, (5.0, 6))], dtype=[('A', 'is;The dtypes argument must be None, a single dtype or a list.RRTRIR/RUN(R8RRkRRR@R R-RiRPR_RfRQRR?R RDRRt masked_allRdR&RRV(R}RRWtdtypesRIRTRUterr_msgR6R0RoR#tmsgRqtntdR((s</usr/lib64/python2.6/site-packages/numpy/lib/recfunctions.pyRs:   6I `  !c Cs%t||d|d|dtdtƒS(sU Add new fields to an existing array. The names of the fields are given with the `names` arguments, the corresponding values with the `data` arguments. If a single field is appended, `names`, `data` and `dtypes` do not have to be lists but just values. Parameters ---------- base : array Input array to extend. names : string, sequence String or sequence of strings corresponding to the names of the new fields. data : array or sequence of arrays Array or sequence of arrays storing the fields to add to the base. dtypes : sequence of datatypes, optional Datatype or sequence of datatypes. If None, the datatypes are estimated from the `data`. See Also -------- append_fields Returns ------- appended_array : np.recarray RWR„RURT(RR_RP(R}RRWR„((s</usr/lib64/python2.6/site-packages/numpy/lib/recfunctions.pyRTscCsXt|tƒo|St|ƒdjo |dSg}|D]}|ti|ƒiƒq<~}g}|D]}|t|ƒql~} g} |D]}| |iq“~ } g} | D]} | | iq·~ }| d}|i}g}|D]}||dqî~}x| dD] }x|iD]ø}|dpd}||jo|i |ƒ|i |ƒq#|i |ƒ}||}|oYti|dƒti|dƒjo.t |ƒ}|d|d>> x = np.array([1, 2,]) >>> stack_arrays(x) is x True >>> z = np.array([('A', 1), ('B', 2)], dtype=[('A', '|S3'), ('B', float)]) >>> zz = np.array([('a', 10., 100.), ('b', 20., 200.), ('c', 30., 300.)], dtype=[('A', '|S3'), ('B', float), ('C', float)]) >>> test = stack_arrays((z,zz)) >>> masked_array(data = [('A', 1.0, --) ('B', 2.0, --) ('a', 10.0, 100.0) ... ('b', 20.0, 200.0) ('c', 30.0, 300.0)], ... mask = [(False, False, True) (False, False, True) (False, False, False) ... (False, False, False) (False, False, False)], ... fill_value=('N/A', 1e+20, 1e+20) ... dtype=[('A', '|S3'), ('B', ' '%s'sf%iRTRUN(R8RRR-t asanyarrayR`RRR&RtindexRkRt TypeErrortdictRRt concatenateRƒtsumtcumsumtr_RfR RVR](tarraysRZRTRUt autoconvertR6R0R.RotnrecordsRqR)t_[4]Rˆtfldnamestdtype_ltnewdescrt_[5]R+Rtdtype_nR&R#tnameidxt current_descrRtoffsettseenR‡Rstj((s</usr/lib64/python2.6/site-packages/numpy/lib/recfunctions.pyRws\% 0'$$  %     ' *   c Csti|ƒiƒ}t|iƒ}|}|o-x||D]}||}q<W||}n|iƒ}||}|iƒ} | d | dj} |o|i} t| | d>> ndtype = [('a', int)] >>> a = ma.array([1, 1, 1, 2, 2, 3, 3], ... mask=[0, 0, 1, 0, 0, 0, 1]).view(ndtype) >>> find_duplicates(a, ignoremask=True, return_index=True) iÿÿÿÿiN( R-R‰R`R RtargsortRSt recordmaskRPR( R0tkeyt ignoremaskt return_indexR'R}R=tsortidxt sortedbaset sorteddatatflagt sortedmaskt duplicates((s</usr/lib64/python2.6/site-packages/numpy/lib/recfunctions.pyR Ðs*     tinnert1t2c -sÕ|djotd|ƒ‚ntˆtƒo ˆf‰nx\ˆD]T} | |iijotd| ƒ‚n| |iijotd| ƒ‚qEqEW|iƒ}|iƒ}t|ƒt|ƒ} } |ii|ii} } t|g}| D]}|ˆjo ||qøqø~ƒ}t|g}| D]}|ˆjo ||q3q3~ƒ}ti ||fƒ}|i dˆƒ}||}ti t g|d|d jfƒ}|d|d |d *||}||| j}||| j| }t|ƒt|ƒ}}|djod\}}nÒ|djor||}t i |||| jfƒ}t i |||| j| fƒ}t|ƒ|t|ƒ|}}nS|djoE||}t i |||| jfƒ}t|ƒ|d }}n||||}}g} |ii D]}!| t|!ƒq%~ }"|"i‡fd †|ii Dƒƒtd „|"Dƒƒ}#xÒ|ii D]Ä}$t|$ƒ}$|$d } | |#jo}|#i| ƒ}%|"|%}&| ˆjot|$d|&d ƒ|&d  Join arrays `r1` and `r2` on key `key`. The key should be either a string or a sequence of string corresponding to the fields used to join the array. An exception is raised if the `key` field cannot be found in the two input arrays. Neither `r1` nor `r2` should have any duplicates along `key`: the presence of duplicates will make the output quite unreliable. Note that duplicates are not looked for by the algorithm. Parameters ---------- key : {string, sequence} A string or a sequence of strings corresponding to the fields used for comparison. r1, r2 : arrays Structured arrays. jointype : {'inner', 'outer', 'leftouter'}, optional If 'inner', returns the elements common to both r1 and r2. If 'outer', returns the common elements as well as the elements of r1 not in r2 and the elements of not in r2. If 'leftouter', returns the common elements and the elements of r1 not in r2. r1postfix : string, optional String appended to the names of the fields of r1 that are present in r2 but absent of the key. r2postfix : string, optional String appended to the names of the fields of r2 that are present in r1 but absent of the key. defaults : {dictionary}, optional Dictionary mapping field names to the corresponding default values. usemask : {True, False}, optional Whether to return a MaskedArray (or MaskedRecords is `asrecarray==True`) or a ndarray. asrecarray : {False, True}, optional Whether to return a recarray (or MaskedRecords if `usemask==True`) or just a flexible-type ndarray. Notes ----- * The output is sorted along the key. * A temporary array is formed by dropping the fields not in the key for the two arrays and concatenating the result. This array is then sorted, and the common entries selected. The output is constructed by filling the fields with the selected entries. Matching is not preserved if there are some duplicates... Rªtoutert leftoutersWThe 'jointype' argument should be in 'inner', 'outer' or 'leftouter' (got '%s' instead)sr1 does not have key field %ssr2 does not have key field %storderiiÿÿÿÿic3s4x-|]&}|dˆjot|ƒVqqWdS(iN(Rk(R^R+(R¡(s</usr/lib64/python2.6/site-packages/numpy/lib/recfunctions.pys os cssx|]}|dVqWdS(iN((R^R+((s</usr/lib64/python2.6/site-packages/numpy/lib/recfunctions.pys qs RRTRU(RªR­R®(ii(R­R®(RR8R@RRR`RR RRRRŸRPR-R&RkR$RŠRdtinsertRRRƒtsortRŒRVR](-R¡tr1tr2tjointypet r1postfixt r2postfixRZRTRUR#tnb1tnb2tr1namestr2namesR6R‡tr1kRotr2ktauxtidx_sorttflag_intidx_intidx_1tidx_2tr1cmntr2cmntr1spctr2spctidx_outts1ts2RqR+R)RtdescRšRR”tcmnRR=tselectedtkwargs((R¡s</usr/lib64/python2.6/site-packages/numpy/lib/recfunctions.pyR s 4    ;; &    #%  -#      '         c Cs@td|d|d|d|dtdtƒ}t||||S(s¨ Join arrays `r1` and `r2` on keys. Alternative to join_by, that always returns a np.recarray. See Also -------- join_by : equivalent function R´RµR¶RZRTRU(RŒRPR_R (R¡R²R³R´RµR¶RZRÍ((s</usr/lib64/python2.6/site-packages/numpy/lib/recfunctions.pyR¢s (.t__doc__t itertoolsRRFRRERRGtnumpyR-RRtnumpy.maRRRtnumpy.ma.mrecordsRtnumpy.lib._iotoolsRtcoreRct__all__RRR%R(RPR1R R R:RAR_RORVR]R R RRRRRR R R(((s</usr/lib64/python2.6/site-packages/numpy/lib/recfunctions.pytsV     &    / ! ^>  &E #  X5 œ