v]c@`sdZddlmZmZmZddlZddlZddlZddl j Z ddlm Z m Z ddl m Z ddlmZddlmZddlmZdd lmZdd lmZejdd krdd lmZnej jjZd ddddddddddddddddddd d!gZd"Zeed#Zd$Z d%Z!d&Z"d'Z#e$d(Z%e$d)Z&ddd*Z(d+Z)d,Z*de+d-Z,e+e$d.Z-dd/Z.ddddd0Z/ee/d1e$e$e$d2Z0ddd3Z1ee1e+e$d4Z2e+e$d5Z3d6Z4ee4d7Z5d8Z6ee6d9Z7ddddd:Z8ee8dd1e+e$d;Z9dd<Z:ee:dd=Z;ddd>Z<ee<e$e$d?Z=dd@Z>ddddAZ?ee?de$dBdCZ@ddddddDZAeeAdde$e$dBdEZBdFZCeeCdGZDddHZEeeEe+dIZFdJZGeeGdKZHdddddLZIeeIde+e$e$dMZJddddNZKeeKde+e$dOZLdddddddPZMeeMdQdRdSde+e$dTZNdddddUZOeeOdQdRdSddVZPdS(Ws 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(tdivisiontabsolute_importtprint_functionN(tndarraytrecarray(t MaskedArray(t MaskedRecords(tarray_function_dispatch(t_is_string_like(t basestring(tsuppress_warningsi(tzipt append_fieldstapply_along_fieldstassign_fields_by_namet drop_fieldstfind_duplicatest flatten_descrtget_fieldstructuret get_namestget_names_flattjoin_byt merge_arraystrec_append_fieldstrec_drop_fieldstrec_jointrecursive_fill_fieldst rename_fieldst repack_fieldstrequire_fieldst stack_arrayststructured_to_unstructuredtunstructured_to_structuredcC`s ||fS(N((tinputtoutput((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyt!_recursive_fill_fields_dispatcher'scC`sz|j}xj|jD]_}y||}Wntk r=qnX|jjr^t|||q|||t|*qW|S(sj 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 -------- >>> from numpy.lib import recfunctions as rfn >>> a = np.array([(1, 10.), (2, 20.)], dtype=[('A', np.int64), ('B', np.float64)]) >>> b = np.zeros((3,), dtype=a.dtype) >>> rfn.recursive_fill_fields(a, b) array([(1, 10.), (2, 20.), (0, 0.)], dtype=[('A', '\}}t|dkr`|n |d|f|df^q<SdS(sR Produce a list of name/dtype pairs corresponding to the dtype fields Similar to dtype.descr, but the second item of each tuple is a dtype, not a string. As a result, this handles subarray dtypes Can be passed to the dtype constructor to reconstruct the dtype, noting that this (deliberately) discards field offsets. Examples -------- >>> dt = np.dtype([(('a', 'A'), np.int64), ('b', np.double, 3)]) >>> dt.descr [(('a', 'A'), '>> _get_fieldspec(dt) [(('a', 'A'), dtype('int64')), ('b', dtype(('isiiN(R%tNoneR'(R$R,R.tf((R$sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyt_get_fieldspecRs  cC`srg}|j}xP|D]H}||}|jrQ|j|tt|fq|j|qWt|pqdS(s Returns the field names of the input datatype as a tuple. Parameters ---------- adtype : dtype Input datatype Examples -------- >>> from numpy.lib import recfunctions as rfn >>> rfn.get_names(np.empty((1,), dtype=int)) Traceback (most recent call last): ... AttributeError: 'numpy.ndarray' object has no attribute 'names' >>> rfn.get_names(np.empty((1,), dtype=[('A',int), ('B', float)])) Traceback (most recent call last): ... AttributeError: 'numpy.ndarray' object has no attribute 'names' >>> adtype = np.dtype([('a', int), ('b', [('ba', int), ('bb', int)])]) >>> rfn.get_names(adtype) ('a', ('b', ('ba', 'bb'))) N(R%tappendttupleRR/(tadtypet listnamesR%R.R*((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyRqs    "cC`sfg}|j}xD|D]<}|j|||}|jr|jt|qqWt|pedS(s  Returns the field names of the input datatype as a tuple. Nested structure are flattened beforehand. Parameters ---------- adtype : dtype Input datatype Examples -------- >>> from numpy.lib import recfunctions as rfn >>> rfn.get_names_flat(np.empty((1,), dtype=int)) is None Traceback (most recent call last): ... AttributeError: 'numpy.ndarray' object has no attribute 'names' >>> rfn.get_names_flat(np.empty((1,), dtype=[('A',int), ('B', float)])) Traceback (most recent call last): ... AttributeError: 'numpy.ndarray' object has no attribute 'names' >>> adtype = np.dtype([('a', int), ('b', [('ba', int), ('bb', int)])]) >>> rfn.get_names_flat(adtype) ('a', 'b', 'ba', 'bb') N(R%R2textendRR3R/(R4R5R%R.R*((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyRs     cC`s|j}|dkr"d|ffSg}xS|D]K}|j|\}}|jrg|jt|q/|j||fq/Wt|SdS(sD Flatten a structured data-type description. Examples -------- >>> from numpy.lib import recfunctions as rfn >>> ndtype = np.dtype([('a', '>> rfn.flatten_descr(ndtype) (('a', dtype('int32')), ('ba', dtype('float64')), ('bb', dtype('int32'))) R+N(R%R/R,R6RR2R3(tndtypeR%tdescrR)ttypt_((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyRs     cC`sg}|r6x|D]}|jt|jqWnax^|D]V}|j}|jrt|jdkr|jt|q=|jd|fq=Wtj|S(NiR+(R6RR$R%R'R1R2tnp(t seqarraystflattenR(taR*((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyt _zip_dtypes   cC`st|d|jS(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. R=(R?R8(R<R=((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyt _zip_descrs cC`s|dkri}n|j}x|D]}||}|jrz|rT|g||>> from numpy.lib import recfunctions as rfn >>> ndtype = np.dtype([('A', int), ... ('B', [('BA', int), ... ('BB', [('BBA', int), ('BBB', int)])])]) >>> rfn.get_fieldstructure(ndtype) ... # XXX: possible regression, order of BBA and BBB is swapped {'A': [], 'B': [], 'BA': ['B'], 'BB': ['B'], 'BBA': ['B', 'BB'], 'BBB': ['B', 'BB']} N(R/R%tupdateRtgetR2(R4tlastnametparentsR%R.R*R:t lastparent((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyRs"       + cc`sQxJ|D]B}t|tjrDx'tt|D] }|Vq2Wq|VqWdS(su Returns an iterator of concatenated fields from a sequence of arrays, collapsing any nested structure. N(t isinstanceR;tvoidt_izip_fields_flatR3(titerabletelementR0((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyRHs   cc`sx|D]}t|drKt|t rKxjt|D] }|Vq9Wqt|tjrtt|dkrx!t|D] }|VqWq|VqWdS(sP Returns an iterator of concatenated fields from a sequence of arrays. t__iter__iN(thasattrRFR t _izip_fieldsR;RGR'R3(RIRJR0((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyRM-s  * cc`so|rt}nt}tjddkr4tj}n tj}x+|d||D]}t||VqPWdS(s* Returns an iterator of concatenated items from a sequence of arrays. Parameters ---------- seqarrays : sequence of arrays Sequence of arrays. fill_value : {None, integer} Value used to pad shorter iterables. flatten : {True, False}, Whether to iit fillvalueN(RHRMtsyst version_infot itertoolst zip_longestt izip_longestR3(R<t fill_valueR=tzipfuncRRttup((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyt _izip_records>s   cC`sdt|tst}n|r9|r`|jt}q`n'tj|}|r`|jt}n|S(s Private function: return a recarray, a ndarray, a MaskedArray or a MaskedRecords depending on the input parameters (RFRtFalsetviewRtmatfilledR(R"tusemaskt asrecarray((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyt _fix_output[s cC`s{|jj}|j|j|j}}}xK|p5ijD]7\}}||kr<|||<|||||>> from numpy.lib import recfunctions as rfn >>> rfn.merge_arrays((np.array([1, 2]), np.array([10., 20., 30.]))) array([( 1, 10.), ( 2, 20.), (-1, 30.)], dtype=[('f0', '>> rfn.merge_arrays((np.array([1, 2], dtype=np.int64), ... np.array([10., 20., 30.])), usemask=False) array([(1, 10.0), (2, 20.0), (-1, 30.0)], dtype=[('f0', '>> rfn.merge_arrays((np.array([1, 2]).view([('a', np.int64)]), ... np.array([10., 20., 30.])), ... usemask=False, asrecarray=True) rec.array([( 1, 10.), ( 2, 20.), (-1, 30.)], dtype=[('a', '((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pys stndmintcountR`(iN( R'R;t asanyarrayRFRRGR$R%R?tTruetravelRRRRYR3tmaxR t __array__RZt getmaskarrayt_check_fill_valuetitemtarraytonesR/R2RQtchainRWtfromitertlist(R<RTR=R\R]tseqdtypetseqtypet_mtsizest maxlengthR(tseqdatatseqmaskR>tnt nbmissingR_R`tfvaltfmskR"((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyRsz1  "     "    $! $$cC`s|fS(N((tbaset drop_namesR\R]((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyt_drop_fields_dispatchersc`st|r|g}n t|}fd|j|}|sOdStj|jd|}t||}t|d|d|S(sn 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, optional Whether to return a recarray or a mrecarray (`asrecarray=True`) or a plain ndarray or masked array with flexible dtype. The default is False. Examples -------- >>> from numpy.lib import recfunctions as rfn >>> a = np.array([(1, (2, 3.0)), (4, (5, 6.0))], ... dtype=[('a', np.int64), ('b', [('ba', np.double), ('bb', np.int64)])]) >>> rfn.drop_fields(a, 'a') array([((2., 3),), ((5., 6),)], dtype=[('b', [('ba', '>> rfn.drop_fields(a, 'ba') array([(1, (3,)), (4, (6,))], dtype=[('a', '>> rfn.drop_fields(a, ['ba', 'bb']) array([(1,), (4,)], dtype=[('a', '>> from numpy.lib import recfunctions as rfn >>> a = np.array([(1, (2, [3.0, 30.])), (4, (5, [6.0, 60.]))], ... dtype=[('a', int),('b', [('ba', float), ('bb', (float, 2))])]) >>> rfn.rename_fields(a, {'a':'A', 'bb':'BB'}) array([(1, (2., [ 3., 30.])), (4, (5., [ 6., 60.]))], dtype=[('A', 'R.RRR"((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyR s<    .@ X  cc`s|Vx|D] }|Vq WdS(N((RR%R_RR((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyt_rec_append_fields_dispatchers c C`s%t||d|d|dtdtS(sM 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 R_RR]R\(R RlRX(RR%R_R((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyRscC`s|fS(N((R>taligntrecurse((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyt_repack_fields_dispatcherscC`s t|tjs@t|jd|d|}|j|dtS|jdkrS|Sg}x|jD]z}|j|}|rt|dd|dt }n |d}t |dkr|d|f}n|j ||fqcWtj|d|}tj|j |fS(s Re-pack the fields of a structured array or dtype in memory. The memory layout of structured datatypes allows fields at arbitrary byte offsets. This means the fields can be separated by padding bytes, their offsets can be non-monotonically increasing, and they can overlap. This method removes any overlaps and reorders the fields in memory so they have increasing byte offsets, and adds or removes padding bytes depending on the `align` option, which behaves like the `align` option to `np.dtype`. If `align=False`, this method produces a "packed" memory layout in which each field starts at the byte the previous field ended, and any padding bytes are removed. If `align=True`, this methods produces an "aligned" memory layout in which each field's offset is a multiple of its alignment, and the total itemsize is a multiple of the largest alignment, by adding padding bytes as needed. Parameters ---------- a : ndarray or dtype array or dtype for which to repack the fields. align : boolean If true, use an "aligned" memory layout, otherwise use a "packed" layout. recurse : boolean If True, also repack nested structures. Returns ------- repacked : ndarray or dtype Copy of `a` with fields repacked, or `a` itself if no repacking was needed. Examples -------- >>> from numpy.lib import recfunctions as rfn >>> def print_offsets(d): ... print("offsets:", [d.fields[name][1] for name in d.names]) ... print("itemsize:", d.itemsize) ... >>> dt = np.dtype('u1, >> dt dtype({'names':['f0','f1','f2'], 'formats':['u1','>> print_offsets(dt) offsets: [0, 8, 16] itemsize: 24 >>> packed_dt = rfn.repack_fields(dt) >>> packed_dt dtype([('f0', 'u1'), ('f1', '>> print_offsets(packed_dt) offsets: [0, 1, 9] itemsize: 17 RRRiiiN( RFR;R$RtastypeRXR%R/R,RlR'R2Rg(R>RRtdtt fieldinfoR.RVtfmt((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyRs :  c C`s"d}g}x |jD]}|j|}|d|d}}||\}}|jdkr|jtj||ff|||fqt|||} |j} xjt|D]\} | dkr|j | q|j g| D]&\} } }| | || | f^qqWqW|S(s Returns a flat list of (dtype, count, offset) tuples of all the scalar fields in the dtype "dt", including nested fields, in left to right order. cS`sMd}x:|jdkrBx|jD]}||9}q"W|j}q W||fS(Ni((RR(RRjRh((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyt count_elemps  iiN( R%R,R/R2R;R$t_get_fields_and_offsetstitemsizetrangeR6(RtoffsetRR,R.R)tf_dttf_offsetRt subfieldsRhtiRtcto((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyRgs  /  BcC`s|fS(N((tarrR$Rtcasting((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyt&_structured_to_unstructured_dispatcherstunsafecC`s|jjd kr!tdnt|j}t|}|dkrc|d krctdn|dkr~tdnt|\}}}gt|D]} dj | ^q} |d krt j g|D]} | j ^q} n|} t ji| d6|d6|d6|jj d 6} t&}|jtd |j| }Wd QXt ji| d6g|D]} | | jf^qnd6}|j|d |d |}|j| t|ffS(sp Converts and n-D structured array into an (n+1)-D unstructured array. The new array will have a new last dimension equal in size to the number of field-elements of the input array. If not supplied, the output datatype is determined from the numpy type promotion rules applied to all the field datatypes. Nested fields, as well as each element of any subarray fields, all count as a single field-elements. Parameters ---------- arr : ndarray Structured array or dtype to convert. Cannot contain object datatype. dtype : dtype, optional The dtype of the output unstructured array. copy : bool, optional See copy argument to `ndarray.astype`. If true, always return a copy. If false, and `dtype` requirements are satisfied, a view is returned. casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional See casting argument of `ndarray.astype`. Controls what kind of data casting may occur. Returns ------- unstructured : ndarray Unstructured array with one more dimension. Examples -------- >>> from numpy.lib import recfunctions as rfn >>> a = np.zeros(4, dtype=[('a', 'i4'), ('b', 'f4,u2'), ('c', 'f4', 2)]) >>> a array([(0, (0., 0), [0., 0.]), (0, (0., 0), [0., 0.]), (0, (0., 0), [0., 0.]), (0, (0., 0), [0., 0.])], dtype=[('a', '>> rfn.structured_to_unstructured(a) array([[0., 0., 0., 0., 0.], [0., 0., 0., 0., 0.], [0., 0., 0., 0., 0.], [0., 0., 0., 0., 0.]]) >>> b = np.array([(1, 2, 5), (4, 5, 7), (7, 8 ,11), (10, 11, 12)], ... dtype=[('x', 'i4'), ('y', 'f4'), ('z', 'f8')]) >>> np.mean(rfn.structured_to_unstructured(b[['x', 'z']]), axis=-1) array([ 3. , 5.5, 9. , 11. ]) sarr must be a structured arrayis(arr has no fields. Unable to guess dtypes#arr with no fields is not supportedsf{}R%tformatstoffsetsRsNumpy has detectedNRR(R$R%R/R&RR'tNotImplementedErrorR RtformatR;t result_typeRRR tfiltert FutureWarningRYRRtsum(RR$RRR,tn_fieldstdtstcountsRRR%Rt out_dtypetflattened_fieldstsupt packed_fields((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyRs04  ( ( )cC`s|fS(N((RR$R%RRR((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyt&_unstructured_to_structured_dispatcherscC`se|jdkrtdn|jd}|dkrFtdn|dkr|dkrgt|D]}dj|^qk}ntjg|D]}||jf^qd|}t|} t | \} } } n|dk rtdnt|} t | dkr.ggg} } } nt | \} } } |t | krdtdn|}|r|j rtd ngtt | D]}dj|^q}tji|d 6g| D]} |j| jf^qd 6}tj |j|}tji|d 6| d 6| d 6|jd 6}|j|d|d|}|j|dS(s Converts and n-D unstructured array into an (n-1)-D structured array. The last dimension of the input array is converted into a structure, with number of field-elements equal to the size of the last dimension of the input array. By default all output fields have the input array's dtype, but an output structured dtype with an equal number of fields-elements can be supplied instead. Nested fields, as well as each element of any subarray fields, all count towards the number of field-elements. Parameters ---------- arr : ndarray Unstructured array or dtype to convert. dtype : dtype, optional The structured dtype of the output array names : list of strings, optional If dtype is not supplied, this specifies the field names for the output dtype, in order. The field dtypes will be the same as the input array. align : boolean, optional Whether to create an aligned memory layout. copy : bool, optional See copy argument to `ndarray.astype`. If true, always return a copy. If false, and `dtype` requirements are satisfied, a view is returned. casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional See casting argument of `ndarray.astype`. Controls what kind of data casting may occur. Returns ------- structured : ndarray Structured array with fewer dimensions. Examples -------- >>> from numpy.lib import recfunctions as rfn >>> dt = np.dtype([('a', 'i4'), ('b', 'f4,u2'), ('c', 'f4', 2)]) >>> a = np.arange(20).reshape((4,5)) >>> a array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19]]) >>> rfn.unstructured_to_structured(a, dt) array([( 0, ( 1., 2), [ 3., 4.]), ( 5, ( 6., 7), [ 8., 9.]), (10, (11., 12), [13., 14.]), (15, (16., 17), [18., 19.])], dtype=[('a', '>> from numpy.lib import recfunctions as rfn >>> b = np.array([(1, 2, 5), (4, 5, 7), (7, 8 ,11), (10, 11, 12)], ... dtype=[('x', 'i4'), ('y', 'f4'), ('z', 'f8')]) >>> rfn.apply_along_fields(np.mean, b) array([ 2.66666667, 5.33333333, 8.66666667, 11. ]) >>> rfn.apply_along_fields(np.mean, b[['x', 'z']]) array([ 3. , 5.5, 9. , 11. ]) sarr must be a structured arraytaxisiN(R$R%R/R&R(RRtuarr((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyR \s# cC`s ||fS(N((tdsttsrctzero_unassigned((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyt!_assign_fields_by_name_dispatcherscC`s{|jjdkr ||d= 1.14, assignment of one structured array to another copies fields "by position", meaning that the first field from the src is copied to the first field of the dst, and so on, regardless of field name. This function instead copies "by field name", such that fields in the dst are assigned from the identically named field in the src. This applies recursively for nested structures. This is how structure assignment worked in numpy >= 1.6 to <= 1.13. Parameters ---------- dst : ndarray src : ndarray The source and destination arrays during assignment. zero_unassigned : bool, optional If True, fields in the dst for which there was no matching field in the src are filled with the value 0 (zero). This was the behavior of numpy <= 1.13. If False, those fields are not modified. .Ni(R$R%R/R(RRRR.((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyRs cC`s|fS(N((Rstrequired_dtype((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyt_require_fields_dispatcherscC`s)tj|jd|}t|||S(s Casts a structured array to a new dtype using assignment by field-name. This function assigns from the old to the new array by name, so the value of a field in the output array is the value of the field with the same name in the source array. This has the effect of creating a new ndarray containing only the fields "required" by the required_dtype. If a field name in the required_dtype does not exist in the input array, that field is created and set to 0 in the output array. Parameters ---------- a : ndarray array to cast required_dtype : dtype datatype for output array Returns ------- out : ndarray array with the new dtype, with field values copied from the fields in the input array with the same name Examples -------- >>> from numpy.lib import recfunctions as rfn >>> a = np.ones(4, dtype=[('a', 'i4'), ('b', 'f8'), ('c', 'u1')]) >>> rfn.require_fields(a, [('b', 'f4'), ('c', 'u1')]) array([(1., 1), (1., 1), (1., 1), (1., 1)], dtype=[('b', '>> rfn.require_fields(a, [('b', 'f4'), ('newf', 'u1')]) array([(1., 0), (1., 0), (1., 0), (1., 0)], dtype=[('b', '>> from numpy.lib import recfunctions as rfn >>> x = np.array([1, 2,]) >>> rfn.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', np.double), ('C', np.double)]) >>> test = rfn.stack_arrays((z,zz)) >>> test masked_array(data=[(b'A', 1.0, --), (b'B', 2.0, --), (b'a', 10.0, 100.0), (b'b', 20.0, 200.0), (b'c', 30.0, 300.0)], mask=[(False, False, True), (False, False, True), (False, False, False), (False, False, False), (False, False, False)], fill_value=(b'N/A', 1.e+20, 1.e+20), dtype=[('A', 'S3'), ('B', ' '%s'isf%iR\R]N(RFRR'R;RkRmR$R%R1R2tindexRnt TypeErrorRZt concatenateRRtcumsumtr_R R/R^Re(RRbR\R]RR>R<tnrecordsR7Rtfldnamestdtype_ltnewdescrRR%tdtype_ntfnametfdtypetnameidxR:tcdtypeR"RtseenRtjR.((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyRsL)(    0    cC`s|fS(N((R>tkeyt ignoremaskt return_index((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyt_find_duplicates_dispatcher<sc C`s tj|j}t|j}|}|r\x||D]}||}q;W||}n|j}||}|j} | d | dk} |r|j} t| | d>> from numpy.lib import recfunctions as rfn >>> ndtype = [('a', int)] >>> a = np.ma.array([1, 1, 1, 2, 2, 3, 3], ... mask=[0, 0, 1, 0, 0, 0, 1]).view(ndtype) >>> rfn.find_duplicates(a, ignoremask=True, return_index=True) (masked_array(data=[(1,), (1,), (2,), (2,)], mask=[(False,), (False,), (False,), (False,)], fill_value=(999999,), dtype=[('a', 'RRRR,RR0tsortidxt sortedbaset sorteddatatflagt sortedmaskt duplicates((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyRAs(     c C`s ||fS(N(( Rtr1tr2tjointypet r1postfixt r2postfixRbR\R]((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyt_join_by_dispatcher{stinnert1t2c .`s2|dkrtd|nttr:fntttkrtfdtD} td| nxXD]P} | |jjkrtd| n| |jjkrtd| qqW|j }|j }t|} |jj|jj} } t| t| @t}|rw|pT| rwd }|d 7}t|ng| D]}|kr~|^q~}t ||}t ||}t j ||f}|j d }||}t j tg|d |d kf}|d |d |d *||}||| k}||| k| }t|t|}}|dkrd\}}n|dkr||}tj |||| kf}tj |||| k| f}t||t||}}nP|dkrV||}tj |||| kf}t||d}}n||||}} t|j}!x?t|jD].\}"}#|"kr|!j|"|#fqqWxt|jD]\}"}#td|!D}$y|$j|"}%Wn$tk r'|!j|"|#fqX|!|%\}&}'|"kr`|"t|#|'f|!|%ssduplicate join key %rsr1 does not have key field %rsr2 does not have key field %rs8r1 and r2 contain common names, r1postfix and r2postfix scan't both be emptytorderiiics`s|]\}}|VqdS(N((R-R.R$((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pys sR$R\R](RRR(ii(RR(R&RFR R'Rtnextt enumerateR$R%RmRRZRRRXR;R1R2RwRRnRtsorttdictR^Re(.RRRRRRRbR\R]tdupR.tnb1tr1namestr2namest collisionsRRtkey1tr1ktr2ktauxtidx_sorttflag_intidx_intidx_1tidx_2tr1cmntr2cmntr1spctr2spctidx_outts1ts2R7RRR%RR:RtcmnR"R0tselectedR*tkwargs((Rsf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyRs4   "      % &    #$      "    +     +  cC`s ||fS(N((RRRRRRRb((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyt_rec_join_dispatcher5sc C`s@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 RRRRbR\R](RRXRlR(RRRRRRRbR((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyR;s (Qt__doc__t __future__RRRRORQtnumpyR;tnumpy.maRZRRRtnumpy.ma.mrecordsRtnumpy.core.overridesRtnumpy.lib._iotoolsRt numpy.compatR t numpy.testingR RPtfuture_builtinsR tcoreRqt__all__R#RR1RRRRXR?R@R/RRHRMRlRWR^ReRfRRRRRRRRRR RRRRRRRRR RR RRRRRRRRRRRR(((sf/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/recfunctions.pyts          '  $ #   /     >  ( E  " P &  [  f +  % ,  W :