zmc
2023-10-12 ed135d79df12a2466b52dae1a82326941211dcc9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
U
O±dô–ã@sPdZddlZddlmZddlmZddlmZddlm    Z
ddl m Z dd    l mZdd
lmZd d d dddddgZejZdddddddddddddddœZe
jZdd„ZedƒGdd „d ƒƒZGdd „d e
jƒZGdd „d eƒZdd „Zed!ƒd+d#d„ƒZed!ƒd,d$d„ƒZed!ƒd-d%d„ƒZd&d'„Zed!ƒd.d(d„ƒZ ed!ƒd/d*d„ƒZ!dS)0a‚
Record Arrays
=============
Record arrays expose the fields of structured arrays as properties.
 
Most commonly, ndarrays contain elements of a single type, e.g. floats,
integers, bools etc.  However, it is possible for elements to be combinations
of these using structured types, such as::
 
  >>> a = np.array([(1, 2.0), (1, 2.0)], dtype=[('x', np.int64), ('y', np.float64)])
  >>> a
  array([(1, 2.), (1, 2.)], dtype=[('x', '<i8'), ('y', '<f8')])
 
Here, each element consists of two fields: x (and int), and y (a float).
This is known as a structured array.  The different fields are analogous
to columns in a spread-sheet.  The different fields can be accessed as
one would a dictionary::
 
  >>> a['x']
  array([1, 1])
 
  >>> a['y']
  array([2., 2.])
 
Record arrays allow us to access fields as properties::
 
  >>> ar = np.rec.array(a)
 
  >>> ar.x
  array([1, 1])
 
  >>> ar.y
  array([2., 2.])
 
éN)ÚCounter)Ú nullcontexté)Únumeric)Ú numerictypes)Ú    os_fspath)Ú
set_module)Ú_get_legacy_print_modeÚrecordÚrecarrayÚ format_parserÚ
fromarraysÚ fromrecordsÚ
fromstringÚfromfileÚarrayú>ú<ú=Úsú|)ÚbÚlÚnÚBÚLÚNÚSrrrrrÚIÚicCsdd„t|ƒ ¡DƒS)z@Find duplication in a list, return a list of duplicated elementscSsg|]\}}|dkr|‘qS©r©)Ú.0ÚitemÚcountsr!r!úId:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\numpy/core/records.pyÚ
<listcomp>Psþz"find_duplicate.<locals>.<listcomp>)rÚitems)Úlistr!r!r%Úfind_duplicateNs
þr)Únumpyc@s4eZdZdZd dd„Zd dd„Zdd    „Zd
d „ZdS)r a‡
    Class to convert formats, names, titles description to a dtype.
 
    After constructing the format_parser object, the dtype attribute is
    the converted data-type:
    ``dtype = format_parser(formats, names, titles).dtype``
 
    Attributes
    ----------
    dtype : dtype
        The converted data-type.
 
    Parameters
    ----------
    formats : str or list of str
        The format description, either specified as a string with
        comma-separated format descriptions in the form ``'f8, i4, a5'``, or
        a list of format description strings  in the form
        ``['f8', 'i4', 'a5']``.
    names : str or list/tuple of str
        The field names, either specified as a comma-separated string in the
        form ``'col1, col2, col3'``, or as a list or tuple of strings in the
        form ``['col1', 'col2', 'col3']``.
        An empty list can be used, in that case default field names
        ('f0', 'f1', ...) are used.
    titles : sequence
        Sequence of title strings. An empty list can be used to leave titles
        out.
    aligned : bool, optional
        If True, align the fields by padding as the C-compiler would.
        Default is False.
    byteorder : str, optional
        If specified, all the fields will be changed to the
        provided byte-order.  Otherwise, the default byte-order is
        used. For all available string specifiers, see `dtype.newbyteorder`.
 
    See Also
    --------
    dtype, typename, sctype2char
 
    Examples
    --------
    >>> np.format_parser(['<f8', '<i4', '<a5'], ['col1', 'col2', 'col3'],
    ...                  ['T1', 'T2', 'T3']).dtype
    dtype([(('T1', 'col1'), '<f8'), (('T2', 'col2'), '<i4'), (('T3', 'col3'), 'S5')])
 
    `names` and/or `titles` can be empty lists. If `titles` is an empty list,
    titles will simply not appear. If `names` is empty, default field names
    will be used.
 
    >>> np.format_parser(['f8', 'i4', 'a5'], ['col1', 'col2', 'col3'],
    ...                  []).dtype
    dtype([('col1', '<f8'), ('col2', '<i4'), ('col3', '<S5')])
    >>> np.format_parser(['<f8', '<i4', '<a5'], [], []).dtype
    dtype([('f0', '<f8'), ('f1', '<i4'), ('f2', 'S5')])
 
    FNcCs&| ||¡| ||¡| |¡dS©N)Ú _parseFormatsÚ_setfieldnamesÚ _createdtype)ÚselfÚformatsÚnamesÚtitlesÚalignedÚ    byteorderr!r!r%Ú__init__“s  zformat_parser.__init__cs¤|dkrtdƒ‚t|tƒr6t dd„t|ƒDƒ|¡}n t ||¡}|j‰ˆdkrht d|fg|¡}|j‰|j}‡fdd„|Dƒ|_‡fdd„|Dƒ|_    t
|ƒ|_ dS)z Parse the field formats NzNeed formats argumentcSsg|]\}}d |¡|f‘qS)zf{})Úformat)r"rZformat_r!r!r%r&Ÿsz/format_parser._parseFormats.<locals>.<listcomp>Úf1csg|]}ˆ|d‘qS©rr!©r"Úkey©Úfieldsr!r%r&©scsg|]}ˆ|d‘qSr r!r9r;r!r%r&ªs) Ú
ValueErrorÚ
isinstancer(ÚsbÚdtypeÚ    enumerater<r1Ú
_f_formatsÚ_offsetsÚlenÚ_nfields)r/r0r3r@Úkeysr!r;r%r,˜s 
þ zformat_parser._parseFormatscCsø|rXt|ƒttfkrn&t|tƒr,| d¡}ntdt|ƒƒ‚dd„|d|j…Dƒ|_    ng|_    |j    dd„t
t |j    ƒ|jƒDƒ7_    t |j    ƒ}|ržt d|ƒ‚|r¾dd„|d|j…Dƒ|_n
g|_g}|jt |ƒkrô|jdg|jt |ƒ7_dS)    zQconvert input field names into a list and assign to the _names
        attribute ú,zillegal input names %scSsg|] }| ¡‘qSr!©Ústrip©r"rr!r!r%r&¹sz0format_parser._setfieldnames.<locals>.<listcomp>NcSsg|] }d|‘qS)zf%dr!©r"rr!r!r%r&ÁszDuplicate field names: %scSsg|] }| ¡‘qSr!rHrJr!r!r%r&És)Útyper(Útupler>ÚstrÚsplitÚ    NameErrorÚreprrEÚ_namesÚrangerDr)r=Ú_titles)r/r1r2Z_dupr!r!r%r-­s(
 ÿ 
 zformat_parser._setfieldnamescCsDt |j|j|j|jdœ¡}|dk    r:t|d}| |¡}||_dS)N)r1r0Úoffsetsr2r)r?r@rRrBrCrTÚ_byteorderconvZ newbyteorder)r/r4r@r!r!r%r.Ñsü 
zformat_parser._createdtype)FN)F)Ú__name__Ú
__module__Ú __qualname__Ú__doc__r5r,r-r.r!r!r!r%r Ws
:
 
$csTeZdZdZdZdZ‡fdd„Z‡fdd„Zdd„Zd    d
„Zd d „Zd d„Z    ‡Z
S)r
zEA data-type scalar that allows field access as attribute lookup.
    r*cstƒdkr| ¡Stƒ ¡S©Néq)r    Ú__str__ÚsuperÚ__repr__©r/©Ú    __class__r!r%r_ès
zrecord.__repr__cs tƒdkrt| ¡ƒStƒ ¡Sr[)r    rNr#r^r]r`rar!r%r]ís
 zrecord.__str__cCsÂ|dkrtj ||¡Sztj ||¡WStk
r:YnXtj |d¡j}| |d¡}|r²|j|dd…Ž}z
|j}Wntk
r|YSX|jdk    r®|     |j
|jf¡S|Std|ƒ‚dS)N©ÚsetfieldÚgetfieldr@r@éú%'record' object has no attribute '%s') ÚntÚvoidÚ__getattribute__ÚAttributeErrorr<Úgetrer@r1Úviewrb)r/ÚattrÚ    fielddictÚresÚobjÚdtr!r!r%rjòs( 
 
 
ÿzrecord.__getattribute__cCsx|dkrtd|ƒ‚tj |d¡j}| |d¡}|rL|j|f|dd…žŽSt||dƒrhtj |||¡Std|ƒ‚dS)NrczCannot set '%s' attributer@rfrg)    rkrhrirjr<rlrdÚgetattrÚ __setattr__)r/rnÚvalrorpr!r!r%rt s   ÿzrecord.__setattr__cCs@tj ||¡}t|tjƒr8|jjdk    r8| |j|jf¡S|SdSr+)rhriÚ __getitem__r>r@r1rmrb©r/Zindxrqr!r!r%rvszrecord.__getitem__cs@ˆjj}tdd„|Dƒƒ}d|‰‡‡fdd„|Dƒ}d |¡S)zPretty-print all fields.css|]}t|ƒVqdSr+)rD©r"Únamer!r!r%Ú    <genexpr>'sz record.pprint.<locals>.<genexpr>z %% %ds: %%scsg|]}ˆ|tˆ|ƒf‘qSr!)rsrx©Úfmtr/r!r%r&)sz!record.pprint.<locals>.<listcomp>Ú
)r@r1ÚmaxÚjoin)r/r1ÚmaxlenÚrowsr!r{r%Úpprint#s
z record.pprint) rWrXrYrZr_r]rjrtrvr‚Ú __classcell__r!r!rar%r
ßs  
c
s\eZdZdZdZdZddd„Zd    d
„Zd d „Zd d„Z‡fdd„Zdd„Z    ddd„Z
‡Z S)r a-Construct an ndarray that allows field access using attributes.
 
    Arrays may have a data-types containing fields, analogous
    to columns in a spread sheet.  An example is ``[(x, int), (y, float)]``,
    where each entry in the array is a pair of ``(int, float)``.  Normally,
    these attributes are accessed using dictionary lookups such as ``arr['x']``
    and ``arr['y']``.  Record arrays allow the fields to be accessed as members
    of the array, using ``arr.x`` and ``arr.y``.
 
    Parameters
    ----------
    shape : tuple
        Shape of output array.
    dtype : data-type, optional
        The desired data-type.  By default, the data-type is determined
        from `formats`, `names`, `titles`, `aligned` and `byteorder`.
    formats : list of data-types, optional
        A list containing the data-types for the different columns, e.g.
        ``['i4', 'f8', 'i4']``.  `formats` does *not* support the new
        convention of using types directly, i.e. ``(int, float, int)``.
        Note that `formats` must be a list, not a tuple.
        Given that `formats` is somewhat limited, we recommend specifying
        `dtype` instead.
    names : tuple of str, optional
        The name of each column, e.g. ``('x', 'y', 'z')``.
    buf : buffer, optional
        By default, a new array is created of the given shape and data-type.
        If `buf` is specified and is an object exposing the buffer interface,
        the array will use the memory from the existing buffer.  In this case,
        the `offset` and `strides` keywords are available.
 
    Other Parameters
    ----------------
    titles : tuple of str, optional
        Aliases for column names.  For example, if `names` were
        ``('x', 'y', 'z')`` and `titles` is
        ``('x_coordinate', 'y_coordinate', 'z_coordinate')``, then
        ``arr['x']`` is equivalent to both ``arr.x`` and ``arr.x_coordinate``.
    byteorder : {'<', '>', '='}, optional
        Byte-order for all fields.
    aligned : bool, optional
        Align the fields in memory as the C-compiler would.
    strides : tuple of ints, optional
        Buffer (`buf`) is interpreted according to these strides (strides
        define how many bytes each array element, row, column, etc.
        occupy in memory).
    offset : int, optional
        Start reading buffer (`buf`) from this offset onwards.
    order : {'C', 'F'}, optional
        Row-major (C-style) or column-major (Fortran-style) order.
 
    Returns
    -------
    rec : recarray
        Empty array of the given shape and type.
 
    See Also
    --------
    core.records.fromrecords : Construct a record array from data.
    record : fundamental data-type for `recarray`.
    format_parser : determine a data-type from formats, names, titles.
 
    Notes
    -----
    This constructor can be compared to ``empty``: it creates a new record
    array but does not fill it with data.  To create a record array from data,
    use one of the following methods:
 
    1. Create a standard ndarray and convert it to a record array,
       using ``arr.view(np.recarray)``
    2. Use the `buf` keyword.
    3. Use `np.rec.fromrecords`.
 
    Examples
    --------
    Create an array with two fields, ``x`` and ``y``:
 
    >>> x = np.array([(1.0, 2), (3.0, 4)], dtype=[('x', '<f8'), ('y', '<i8')])
    >>> x
    array([(1., 2), (3., 4)], dtype=[('x', '<f8'), ('y', '<i8')])
 
    >>> x['x']
    array([1., 3.])
 
    View the array as a record array:
 
    >>> x = x.view(np.recarray)
 
    >>> x.x
    array([1., 3.])
 
    >>> x.y
    array([2, 4])
 
    Create a new, empty record array:
 
    >>> np.recarray((2,),
    ... dtype=[('x', int), ('y', float), ('z', int)]) #doctest: +SKIP
    rec.array([(-1073741821, 1.2249118382103472e-301, 24547520),
           (3471280, 1.2134086255804012e-316, 0)],
          dtype=[('x', '<i4'), ('y', '<f8'), ('z', '<i4')])
 
    r*NrFÚCc     Csf|dk    rt |¡} nt||||
|    ƒj} |dkrFtj||t| f| d} ntj||t| f|||| d} | S)N)Úorder)ÚbufferÚoffsetÚstridesr…)r?r@r ÚndarrayÚ__new__r
)ÚsubtypeÚshaper@Úbufr‡rˆr0r1r2r4r3r…Údescrr/r!r!r%rŠ¢s þzrecarray.__new__cCs$|jjtk    r |jjdk    r |j|_dSr+)r@rLr
r1)r/rqr!r!r%Ú__array_finalize__³szrecarray.__array_finalize__c
CsÊzt ||¡WStk
r"YnXt |d¡j}z||dd…}Wn4ttfk
rz}ztd|ƒ|‚W5d}~XYnX|j|Ž}|jj    dk    r¼t
|jj t j ƒr¸|j|jj |jfdS|S| t¡SdS)Nr@rfzrecarray has no attribute %s©r@)Úobjectrjrkr‰r<Ú    TypeErrorÚKeyErrorrer@r1Ú
issubclassrLrhrirm)r/rnrorpÚerqr!r!r%rj¹s 
 zrecarray.__getattribute__c
Cs$|dkr.t|jtjƒr.|jdk    r.t t|f¡}||jk}zt     
|||¡}Wn0t k
rzt   |d¡jpji}||krv‚YnNXt   |d¡jpŒi}||krš|S|rÈzt     ||¡Wnt k
rÆ|YSXz||dd…}Wn6ttfk
r}ztd|ƒ|‚W5d}~XYnX|j|f|žŽS)Nr@rfz record array has no attribute %s)r”rLrhrir1r?r@r
Ú__dict__r‘rtÚ    Exceptionr‰rjr<Ú __delattr__r’r“rkrd)r/rnruZnewattrÚretrorpr•r!r!r%rtÛs4 
 
ÿþzrecarray.__setattr__csptƒ |¡}t|tƒrh|jjdk    rZ| t|ƒ¡}t|jjt    j
ƒrV|j|jj|jfdS|S|jtdSn|SdS)Nr)rL) r^rvr>r‰r@r1rmrLr”rhrirwrar!r%rvüs 
 zrecarray.__getitem__cCs¶|j}|jjtks"t|jjtjƒsF|jtkr<t tj|f¡}d}d}nd}d}|jdksb|jdkrvtj    |d|dd    }nd
t
|jƒf}d d t |ƒ}t ƒd kr¨d |}||||fS)Nz
rec.array(zrec.array(%s,%sdtype=%s)zarray(z)array(%s,%sdtype=%s).view(numpy.recarray)rr8z, rG)Ú    separatorÚprefixÚsuffixz [], shape=%sr}ú r\) r@rLr
r”rhrir?ÚsizerŒZ array2stringrQrDr    )r/Z
repr_dtyper›r|ÚlstÚlfr!r!r%r_ s(
ÿ
zrecarray.__repr__cCs~t|tƒr t |d¡j}||}t |d¡j}||dd…}|dkrj|j|Ž}|jjdk    r`|S| t¡S|j    |f|žŽSdS)Nr@rf)
r>Úintr‰rjr1r<rer@rmrd)r/rnrur1rorprqr!r!r%Úfield.s
 
 
zrecarray.field)
NNrNNNNNFr„)N) rWrXrYrZrŠrrjrtrvr_r¢rƒr!r!rar%r 4s"jþ
"! !cCs$|dkrtjdtdddS|SdS)Nrz¹Passing `shape=0` to have the shape be inferred is deprecated, and in future will be equivalent to `shape=(0,)`. To infer the shape and suppress this warning, pass `shape=None` instead.é©Ú
stacklevel)ÚwarningsÚwarnÚ FutureWarning)rŒr!r!r%Ú_deprecate_shape_0_as_None@sür©z    numpy.recFcCs2dd„|Dƒ}t|ƒ}|dkr*|dj}nt|tƒr:|f}|dkrX|dkrXdd„|Dƒ}|dk    rlt |¡}nt|||||ƒj}|j}    t|ƒt|ƒkrœt    dƒ‚|dj}
t|
ƒ} | dkrÄ|d| …}t
||ƒ} t |ƒD]V\} }|| j } |jd|j | …}|    | }||kr$t    d| ›d|›d    ƒ‚|| |<qÖ| S)
a¶Create a record array from a (flat) list of arrays
 
    Parameters
    ----------
    arrayList : list or tuple
        List of array-like objects (such as lists, tuples,
        and ndarrays).
    dtype : data-type, optional
        valid dtype for all arrays
    shape : int or tuple of ints, optional
        Shape of the resulting array. If not provided, inferred from
        ``arrayList[0]``.
    formats, names, titles, aligned, byteorder :
        If `dtype` is ``None``, these arguments are passed to
        `numpy.format_parser` to construct a dtype. See that function for
        detailed documentation.
 
    Returns
    -------
    np.recarray
        Record array consisting of given arrayList columns.
 
    Examples
    --------
    >>> x1=np.array([1,2,3,4])
    >>> x2=np.array(['a','dd','xyz','12'])
    >>> x3=np.array([1.1,2,3,4])
    >>> r = np.core.records.fromarrays([x1,x2,x3],names='a,b,c')
    >>> print(r[1])
    (2, 'dd', 2.0) # may vary
    >>> x1[1]=34
    >>> r.a
    array([1, 2, 3, 4])
 
    >>> x1 = np.array([1, 2, 3, 4])
    >>> x2 = np.array(['a', 'dd', 'xyz', '12'])
    >>> x3 = np.array([1.1, 2, 3,4])
    >>> r = np.core.records.fromarrays(
    ...     [x1, x2, x3],
    ...     dtype=np.dtype([('a', np.int32), ('b', 'S3'), ('c', np.float32)]))
    >>> r
    rec.array([(1, b'a', 1.1), (2, b'dd', 2. ), (3, b'xyz', 3. ),
               (4, b'12', 4. )],
              dtype=[('a', '<i4'), ('b', 'S3'), ('c', '<f4')])
    cSsg|]}t |¡‘qSr!)r?Zasarray)r"Úxr!r!r%r&}szfromarrays.<locals>.<listcomp>NrcSsg|]
}|j‘qSr!r)r"rqr!r!r%r&Šsz>mismatch between the number of fields and the number of arrayszarray-shape mismatch in array z ("z")) r©rŒr>r¡r?r@r r1rDr=r rAÚndim)Z    arrayListr@rŒr0r1r2r3r4rŽrRZd0ÚnnÚ_arrayÚkrqZ    testshaperyr!r!r%r Ls61 
 
 
 
 
 
c    sL|dkrP|dkrPtj|td‰‡fdd„tˆjdƒDƒ}t|||||||dS|dk    rht t|f¡}    nt|||||ƒj}    ztj||    d}
Wn”t    t
fk
r t |ƒ}|dkrºt |ƒ}t |tƒrÊ|f}t |ƒdkrÞt
dƒ‚t||    ƒ} t| jƒD]} t|| ƒ| | <qòtjd    td
d | YSX|dk    r>|
j|kr>||
_|
 t¡} | S) a Create a recarray from a list of records in text form.
 
    Parameters
    ----------
    recList : sequence
        data in the same field may be heterogeneous - they will be promoted
        to the highest data type.
    dtype : data-type, optional
        valid dtype for all arrays
    shape : int or tuple of ints, optional
        shape of each array.
    formats, names, titles, aligned, byteorder :
        If `dtype` is ``None``, these arguments are passed to
        `numpy.format_parser` to construct a dtype. See that function for
        detailed documentation.
 
        If both `formats` and `dtype` are None, then this will auto-detect
        formats. Use list of tuples rather than list of lists for faster
        processing.
 
    Returns
    -------
    np.recarray
        record array consisting of given recList rows.
 
    Examples
    --------
    >>> r=np.core.records.fromrecords([(456,'dbe',1.2),(2,'de',1.3)],
    ... names='col1,col2,col3')
    >>> print(r[0])
    (456, 'dbe', 1.2)
    >>> r.col1
    array([456,   2])
    >>> r.col2
    array(['dbe', 'de'], dtype='<U3')
    >>> import pickle
    >>> pickle.loads(pickle.dumps(r))
    rec.array([(456, 'dbe', 1.2), (  2, 'de', 1.3)],
              dtype=[('col1', '<i8'), ('col2', '<U3'), ('col3', '<f8')])
    Nrcs"g|]}t ˆd|f ¡¡‘qS).)r?rÚtolistrK©rqr!r%r&Ùszfromrecords.<locals>.<listcomp>éÿÿÿÿ)r0rŒr1r2r3r4rzCan only deal with 1-d array.zxfromrecords expected a list of tuples, may have received a list of lists instead. In the future that will raise an errorrfr¤)r?rr‘rSrŒr r@r
r r’r=r©rDr>r¡r ržrMr¦r§r¨rm)ZrecListr@rŒr0r1r2r3r4ZarrlistrŽÚretvalr­r®rpr!r°r%r«sD,
ÿ
 
ý
 
c     Csx|dkr|dkrtdƒ‚|dk    r,t |¡}    nt|||||ƒj}    |    j}
t|ƒ}|dkrdt|ƒ||
}t||    ||d} | S)aöCreate a record array from binary data
 
    Note that despite the name of this function it does not accept `str`
    instances.
 
    Parameters
    ----------
    datastring : bytes-like
        Buffer of binary data
    dtype : data-type, optional
        Valid dtype for all arrays
    shape : int or tuple of ints, optional
        Shape of each array.
    offset : int, optional
        Position in the buffer to start reading from.
    formats, names, titles, aligned, byteorder :
        If `dtype` is ``None``, these arguments are passed to
        `numpy.format_parser` to construct a dtype. See that function for
        detailed documentation.
 
 
    Returns
    -------
    np.recarray
        Record array view into the data in datastring. This will be readonly
        if `datastring` is readonly.
 
    See Also
    --------
    numpy.frombuffer
 
    Examples
    --------
    >>> a = b'\x01\x02\x03abc'
    >>> np.core.records.fromstring(a, dtype='u1,u1,u1,S3')
    rec.array([(1, 2, 3, b'abc')],
            dtype=[('f0', 'u1'), ('f1', 'u1'), ('f2', 'u1'), ('f3', 'S3')])
 
    >>> grades_dtype = [('Name', (np.str_, 10)), ('Marks', np.float64),
    ...                 ('GradeLevel', np.int32)]
    >>> grades_array = np.array([('Sam', 33.3, 3), ('Mike', 44.4, 5),
    ...                         ('Aadi', 66.6, 6)], dtype=grades_dtype)
    >>> np.core.records.fromstring(grades_array.tobytes(), dtype=grades_dtype)
    rec.array([('Sam', 33.3, 3), ('Mike', 44.4, 5), ('Aadi', 66.6, 6)],
            dtype=[('Name', '<U10'), ('Marks', '<f8'), ('GradeLevel', '<i4')])
 
    >>> s = '\x01\x02\x03abc'
    >>> np.core.records.fromstring(s, dtype='u1,u1,u1,S3')
    Traceback (most recent call last)
       ...
    TypeError: a bytes-like object is required, not 'str'
    Nz2fromstring() needs a 'dtype' or 'formats' argument)Nr±)rr‡)r’r?r@r Úitemsizer©rDr ) Z
datastringr@rŒr‡r0r1r2r3r4rŽr³r­r!r!r%rs8 c
Cs8| ¡}z| dd¡| ¡|W¢S| |d¡XdS)Nrrf)ÚtellÚseek)ÚfdÚposr!r!r%Úget_remaining_sizeKs
 r¸c        Cs\|dkr|dkrtdƒ‚t|ƒ}|dkr.d}nt|tƒr>|f}t|dƒrRt|ƒ}    ntt|ƒdƒ}    |    î}|dkrz| |d¡t    |ƒ}
|dk    r–t
  |¡} nt |||||ƒj } | j } t
 |¡jtjd} | | }|dkr t|ƒ}|
| || d    ¡<t|ƒ}t
 |¡jtjd} | | }||
kr&td
ƒ‚t|| ƒ}| |j¡}||krNtd ƒ‚W5QRX|S) aúCreate an array from binary file data
 
    Parameters
    ----------
    fd : str or file type
        If file is a string or a path-like object then that file is opened,
        else it is assumed to be a file object. The file object must
        support random access (i.e. it must have tell and seek methods).
    dtype : data-type, optional
        valid dtype for all arrays
    shape : int or tuple of ints, optional
        shape of each array.
    offset : int, optional
        Position in the file to start reading from.
    formats, names, titles, aligned, byteorder :
        If `dtype` is ``None``, these arguments are passed to
        `numpy.format_parser` to construct a dtype. See that function for
        detailed documentation
 
    Returns
    -------
    np.recarray
        record array consisting of data enclosed in file.
 
    Examples
    --------
    >>> from tempfile import TemporaryFile
    >>> a = np.empty(10,dtype='f8,i4,a5')
    >>> a[5] = (0.5,10,'abcde')
    >>>
    >>> fd=TemporaryFile()
    >>> a = a.newbyteorder('<')
    >>> a.tofile(fd)
    >>>
    >>> _ = fd.seek(0)
    >>> r=np.core.records.fromfile(fd, formats='f8,i4,a5', shape=10,
    ... byteorder='<')
    >>> print(r[5])
    (0.5, 10, 'abcde')
    >>> r.shape
    (10,)
    Nz0fromfile() needs a 'dtype' or 'formats' argument)r±ÚreadintoÚrbrrrr±z:Not enough bytes left in file for specified shape and typez%Didn't read as many bytes as expected)r’r©r>r¡ÚhasattrrÚopenrrµr¸r?r@r r³rÚprodrhZintpr(ÚindexrMr=r r¹ÚdataÚOSError)r¶r@rŒr‡r0r1r2r3r4ÚctxržrŽr³Z    shapeprodZ    shapesizeÚnbytesr­Z
nbytesreadr!r!r%rTsF.
 
 
 
 
ÿ
 
Tc Cs$t|tdƒtfƒst|dƒr4|dkr4|dkr4tdƒ‚i} |dk    rLt |¡}n,|dk    rht|||||    ƒj}n|||||    dœ} |dkr¢|dkrtdƒ‚t|||||dSt|t    ƒrÄt
||f||dœ| —ŽSt|t t fƒrt|dt t fƒrþt |f||d    œ| —ŽSt|f||d    œ| —ŽSnt|tƒr\|dk    rF|j|krF| |¡} n|} |
rX|  ¡} | St|dƒrxt||||d
St|tƒrÂ|dk    r¦|j|kr¦| |¡} n|} |
r¸|  ¡} |  t¡St|d dƒ} | dksät| tƒsìtd ƒ‚t |¡}|dk    r|j|kr| |¡}| t¡SdS) aŸ
 
    Construct a record array from a wide-variety of objects.
 
    A general-purpose record array constructor that dispatches to the
    appropriate `recarray` creation function based on the inputs (see Notes).
 
    Parameters
    ----------
    obj : any
        Input object. See Notes for details on how various input types are
        treated.
    dtype : data-type, optional
        Valid dtype for array.
    shape : int or tuple of ints, optional
        Shape of each array.
    offset : int, optional
        Position in the file or buffer to start reading from.
    strides : tuple of ints, optional
        Buffer (`buf`) is interpreted according to these strides (strides
        define how many bytes each array element, row, column, etc.
        occupy in memory).
    formats, names, titles, aligned, byteorder :
        If `dtype` is ``None``, these arguments are passed to
        `numpy.format_parser` to construct a dtype. See that function for
        detailed documentation.
    copy : bool, optional
        Whether to copy the input object (True), or to use a reference instead.
        This option only applies when the input is an ndarray or recarray.
        Defaults to True.
 
    Returns
    -------
    np.recarray
        Record array created from the specified object.
 
    Notes
    -----
    If `obj` is ``None``, then call the `~numpy.recarray` constructor. If
    `obj` is a string, then call the `fromstring` constructor. If `obj` is a
    list or a tuple, then if the first object is an `~numpy.ndarray`, call
    `fromarrays`, otherwise call `fromrecords`. If `obj` is a
    `~numpy.recarray`, then make a copy of the data in the recarray
    (if ``copy=True``) and use the new formats, names, and titles. If `obj`
    is a file, then call `fromfile`. Finally, if obj is an `ndarray`, then
    return ``obj.view(recarray)``, making a copy of the data if ``copy=True``.
 
    Examples
    --------
    >>> a = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
    array([[1, 2, 3],
           [4, 5, 6],
           [7, 8, 9]])
 
    >>> np.core.records.array(a)
    rec.array([[1, 2, 3],
               [4, 5, 6],
               [7, 8, 9]],
        dtype=int32)
 
    >>> b = [(1, 1), (2, 4), (3, 9)]
    >>> c = np.core.records.array(b, formats = ['i2', 'f2'], names = ('x', 'y'))
    >>> c
    rec.array([(1, 1.0), (2, 4.0), (3, 9.0)],
              dtype=[('x', '<i2'), ('y', '<f2')])
 
    >>> c.x
    rec.array([1, 2, 3], dtype=int16)
 
    >>> c.y
    rec.array([ 1.0,  4.0,  9.0], dtype=float16)
 
    >>> r = np.rec.array(['abc','def'], names=['col1','col2'])
    >>> print(r.col1)
    abc
 
    >>> r.col1
    array('abc', dtype='<U3')
 
    >>> r.col2
    array('def', dtype='<U3')
    Nr¹zIMust define formats (or dtype) if object is None, string, or an open file)r0r1r2r3r4z"Must define a shape if obj is None)rr‡rˆ)rŒr‡r)r@rŒ)r@rŒr‡Z__array_interface__zUnknown input type)r>rLrNr»r=r?r@r r Úbytesrr(rMrr rmÚcopyrr‰rsÚdictr)rqr@rŒr‡rˆr0r1r2r3r4rÄÚkwdsÚnewZ    interfacer!r!r%r¹sjUÿÿ ÿü
 
 
 
)NNNNNFN)NNNNNFN)NNrNNNFN)NNrNNNFN)
NNrNNNNFNT)"rZr¦Ú collectionsrÚ
contextlibrÚrr?rrhZ numpy.compatrZnumpy.core.overridesrZ
arrayprintr    Ú__all__r‰rVZ
sctypeDictZnumfmtr)r rir
r r©r rrr¸rrr!r!r!r%Ú<module>sž#       þó    U ÿ ^ÿ Tÿ J    ÿ dÿ