MCPcopy
hub / github.com/numpy/numpy / array

Function array

numpy/_core/records.py:943–1089  ·  view source on GitHub ↗

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

(obj, dtype=None, shape=None, offset=0, strides=None, formats=None,
          names=None, titles=None, aligned=False, byteorder=None, copy=True)

Source from the content-addressed store, hash-verified

941
942@set_module("numpy.rec")
943def array(obj, dtype=None, shape=None, offset=0, strides=None, formats=None,
944 names=None, titles=None, aligned=False, byteorder=None, copy=True):
945 """
946 Construct a record array from a wide-variety of objects.
947
948 A general-purpose record array constructor that dispatches to the
949 appropriate `recarray` creation function based on the inputs (see Notes).
950
951 Parameters
952 ----------
953 obj : any
954 Input object. See Notes for details on how various input types are
955 treated.
956 dtype : data-type, optional
957 Valid dtype for array.
958 shape : int or tuple of ints, optional
959 Shape of each array.
960 offset : int, optional
961 Position in the file or buffer to start reading from.
962 strides : tuple of ints, optional
963 Buffer (`buf`) is interpreted according to these strides (strides
964 define how many bytes each array element, row, column, etc.
965 occupy in memory).
966 formats, names, titles, aligned, byteorder :
967 If `dtype` is ``None``, these arguments are passed to
968 `numpy.format_parser` to construct a dtype. See that function for
969 detailed documentation.
970 copy : bool, optional
971 Whether to copy the input object (True), or to use a reference instead.
972 This option only applies when the input is an ndarray or recarray.
973 Defaults to True.
974
975 Returns
976 -------
977 np.recarray
978 Record array created from the specified object.
979
980 Notes
981 -----
982 If `obj` is ``None``, then call the `~numpy.recarray` constructor. If
983 `obj` is a string, then call the `fromstring` constructor. If `obj` is a
984 list or a tuple, then if the first object is an `~numpy.ndarray`, call
985 `fromarrays`, otherwise call `fromrecords`. If `obj` is a
986 `~numpy.recarray`, then make a copy of the data in the recarray
987 (if ``copy=True``) and use the new formats, names, and titles. If `obj`
988 is a file, then call `fromfile`. Finally, if obj is an `ndarray`, then
989 return ``obj.view(recarray)``, making a copy of the data if ``copy=True``.
990
991 Examples
992 --------
993 >>> a = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
994 >>> a
995 array([[1, 2, 3],
996 [4, 5, 6],
997 [7, 8, 9]])
998
999 >>> np.rec.array(a)
1000 rec.array([[1, 2, 3],

Callers 15

test_start_stop_arrayMethod · 0.90
test_base_arrayMethod · 0.90
test_stop_base_arrayMethod · 0.90
test_subclassMethod · 0.90
test_start_stop_arrayMethod · 0.90
test_subclassMethod · 0.90
test_start_stop_arrayMethod · 0.90
test_complexMethod · 0.90
test_subclassMethod · 0.90
test_array_interfaceMethod · 0.90

Calls 9

format_parserClass · 0.85
recarrayClass · 0.85
fromstringFunction · 0.70
fromrecordsFunction · 0.70
fromarraysFunction · 0.70
fromfileFunction · 0.70
dtypeMethod · 0.45
viewMethod · 0.45
copyMethod · 0.45

Tested by 15

test_start_stop_arrayMethod · 0.72
test_base_arrayMethod · 0.72
test_stop_base_arrayMethod · 0.72
test_subclassMethod · 0.72
test_start_stop_arrayMethod · 0.72
test_subclassMethod · 0.72
test_start_stop_arrayMethod · 0.72
test_complexMethod · 0.72
test_subclassMethod · 0.72
test_array_interfaceMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…