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, optio
(arrayList, dtype=None, shape=None, formats=None,
names=None, titles=None, aligned=False, byteorder=None)
| 568 | |
| 569 | @set_module("numpy.rec") |
| 570 | def fromarrays(arrayList, dtype=None, shape=None, formats=None, |
| 571 | names=None, titles=None, aligned=False, byteorder=None): |
| 572 | """Create a record array from a (flat) list of arrays |
| 573 | |
| 574 | Parameters |
| 575 | ---------- |
| 576 | arrayList : list or tuple |
| 577 | List of array-like objects (such as lists, tuples, |
| 578 | and ndarrays). |
| 579 | dtype : data-type, optional |
| 580 | valid dtype for all arrays |
| 581 | shape : int or tuple of ints, optional |
| 582 | Shape of the resulting array. If not provided, inferred from |
| 583 | ``arrayList[0]``. |
| 584 | formats, names, titles, aligned, byteorder : |
| 585 | If `dtype` is ``None``, these arguments are passed to |
| 586 | `numpy.rec.format_parser` to construct a dtype. See that function for |
| 587 | detailed documentation. |
| 588 | |
| 589 | Returns |
| 590 | ------- |
| 591 | np.recarray |
| 592 | Record array consisting of given arrayList columns. |
| 593 | |
| 594 | Examples |
| 595 | -------- |
| 596 | >>> x1=np.array([1,2,3,4]) |
| 597 | >>> x2=np.array(['a','dd','xyz','12']) |
| 598 | >>> x3=np.array([1.1,2,3,4]) |
| 599 | >>> r = np.rec.fromarrays([x1,x2,x3],names='a,b,c') |
| 600 | >>> print(r[1]) |
| 601 | (2, 'dd', 2.0) # may vary |
| 602 | >>> x1[1]=34 |
| 603 | >>> r.a |
| 604 | array([1, 2, 3, 4]) |
| 605 | |
| 606 | >>> x1 = np.array([1, 2, 3, 4]) |
| 607 | >>> x2 = np.array(['a', 'dd', 'xyz', '12']) |
| 608 | >>> x3 = np.array([1.1, 2, 3,4]) |
| 609 | >>> r = np.rec.fromarrays( |
| 610 | ... [x1, x2, x3], |
| 611 | ... dtype=np.dtype([('a', np.int32), ('b', 'S3'), ('c', np.float32)])) |
| 612 | >>> r |
| 613 | rec.array([(1, b'a', 1.1), (2, b'dd', 2. ), (3, b'xyz', 3. ), |
| 614 | (4, b'12', 4. )], |
| 615 | dtype=[('a', '<i4'), ('b', 'S3'), ('c', '<f4')]) |
| 616 | """ |
| 617 | |
| 618 | arrayList = [sb.asarray(x) for x in arrayList] |
| 619 | |
| 620 | # NumPy 1.19.0, 2020-01-01 |
| 621 | shape = _deprecate_shape_0_as_None(shape) |
| 622 | |
| 623 | if shape is None: |
| 624 | shape = arrayList[0].shape |
| 625 | elif isinstance(shape, int): |
| 626 | shape = (shape,) |
| 627 |
no test coverage detected
searching dependent graphs…