MCPcopy Create free account
hub / github.com/numpy/numpy / fromarrays

Function fromarrays

numpy/core/records.py:589–680  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

587
588@set_module("numpy.rec")
589def fromarrays(arrayList, dtype=None, shape=None, formats=None,
590 names=None, titles=None, aligned=False, byteorder=None):
591 """Create a record array from a (flat) list of arrays
592
593 Parameters
594 ----------
595 arrayList : list or tuple
596 List of array-like objects (such as lists, tuples,
597 and ndarrays).
598 dtype : data-type, optional
599 valid dtype for all arrays
600 shape : int or tuple of ints, optional
601 Shape of the resulting array. If not provided, inferred from
602 ``arrayList[0]``.
603 formats, names, titles, aligned, byteorder :
604 If `dtype` is ``None``, these arguments are passed to
605 `numpy.format_parser` to construct a dtype. See that function for
606 detailed documentation.
607
608 Returns
609 -------
610 np.recarray
611 Record array consisting of given arrayList columns.
612
613 Examples
614 --------
615 >>> x1=np.array([1,2,3,4])
616 >>> x2=np.array(['a','dd','xyz','12'])
617 >>> x3=np.array([1.1,2,3,4])
618 >>> r = np.core.records.fromarrays([x1,x2,x3],names='a,b,c')
619 >>> print(r[1])
620 (2, 'dd', 2.0) # may vary
621 >>> x1[1]=34
622 >>> r.a
623 array([1, 2, 3, 4])
624
625 >>> x1 = np.array([1, 2, 3, 4])
626 >>> x2 = np.array(['a', 'dd', 'xyz', '12'])
627 >>> x3 = np.array([1.1, 2, 3,4])
628 >>> r = np.core.records.fromarrays(
629 ... [x1, x2, x3],
630 ... dtype=np.dtype([('a', np.int32), ('b', 'S3'), ('c', np.float32)]))
631 >>> r
632 rec.array([(1, b'a', 1.1), (2, b'dd', 2. ), (3, b'xyz', 3. ),
633 (4, b'12', 4. )],
634 dtype=[('a', '<i4'), ('b', 'S3'), ('c', '<f4')])
635 """
636
637 arrayList = [sb.asarray(x) for x in arrayList]
638
639 # NumPy 1.19.0, 2020-01-01
640 shape = _deprecate_shape_0_as_None(shape)
641
642 if shape is None:
643 shape = arrayList[0].shape
644 elif isinstance(shape, int):
645 shape = (shape,)
646

Callers 2

fromrecordsFunction · 0.70
arrayFunction · 0.70

Calls 4

format_parserClass · 0.85
recarrayClass · 0.85
dtypeMethod · 0.45

Tested by

no test coverage detected