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

Function array

numpy/core/records.py:954–1099  ·  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

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

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