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 : in
(recList, dtype=None, shape=None, formats=None, names=None,
titles=None, aligned=False, byteorder=None)
| 663 | |
| 664 | @set_module("numpy.rec") |
| 665 | def fromrecords(recList, dtype=None, shape=None, formats=None, names=None, |
| 666 | titles=None, aligned=False, byteorder=None): |
| 667 | """Create a recarray from a list of records in text form. |
| 668 | |
| 669 | Parameters |
| 670 | ---------- |
| 671 | recList : sequence |
| 672 | data in the same field may be heterogeneous - they will be promoted |
| 673 | to the highest data type. |
| 674 | dtype : data-type, optional |
| 675 | valid dtype for all arrays |
| 676 | shape : int or tuple of ints, optional |
| 677 | shape of each array. |
| 678 | formats, names, titles, aligned, byteorder : |
| 679 | If `dtype` is ``None``, these arguments are passed to |
| 680 | `numpy.format_parser` to construct a dtype. See that function for |
| 681 | detailed documentation. |
| 682 | |
| 683 | If both `formats` and `dtype` are None, then this will auto-detect |
| 684 | formats. Use list of tuples rather than list of lists for faster |
| 685 | processing. |
| 686 | |
| 687 | Returns |
| 688 | ------- |
| 689 | np.recarray |
| 690 | record array consisting of given recList rows. |
| 691 | |
| 692 | Examples |
| 693 | -------- |
| 694 | >>> r=np.rec.fromrecords([(456,'dbe',1.2),(2,'de',1.3)], |
| 695 | ... names='col1,col2,col3') |
| 696 | >>> print(r[0]) |
| 697 | (456, 'dbe', 1.2) |
| 698 | >>> r.col1 |
| 699 | array([456, 2]) |
| 700 | >>> r.col2 |
| 701 | array(['dbe', 'de'], dtype='<U3') |
| 702 | >>> import pickle |
| 703 | >>> pickle.loads(pickle.dumps(r)) |
| 704 | rec.array([(456, 'dbe', 1.2), ( 2, 'de', 1.3)], |
| 705 | dtype=[('col1', '<i8'), ('col2', '<U3'), ('col3', '<f8')]) |
| 706 | """ |
| 707 | |
| 708 | if formats is None and dtype is None: # slower |
| 709 | obj = sb.array(recList, dtype=object) |
| 710 | arrlist = [ |
| 711 | sb.array(obj[..., i].tolist()) for i in range(obj.shape[-1]) |
| 712 | ] |
| 713 | return fromarrays(arrlist, formats=formats, shape=shape, names=names, |
| 714 | titles=titles, aligned=aligned, byteorder=byteorder) |
| 715 | |
| 716 | if dtype is not None: |
| 717 | descr = sb.dtype((record, dtype)) |
| 718 | else: |
| 719 | descr = format_parser( |
| 720 | formats, names, titles, aligned, byteorder |
| 721 | ).dtype |
| 722 |
no test coverage detected
searching dependent graphs…