bundles / numpy 2.4.4 / numpy / rec / array
function
numpy.rec:array
source: /numpy/_core/records.py :941
Signature
def array ( obj , dtype = None , shape = None , offset = 0 , strides = None , formats = None , names = None , titles = None , aligned = False , byteorder = None , copy = True ) Summary
Construct a record array from a wide-variety of objects.
Extended Summary
A general-purpose record array constructor that dispatches to the appropriate recarray creation function based on the inputs (see Notes).
Parameters
obj: anyInput object. See Notes for details on how various input types are treated.
dtype: data-type, optionalValid dtype for array.
shape: int or tuple of ints, optionalShape of each array.
offset: int, optionalPosition in the file or buffer to start reading from.
strides: tuple of ints, optionalBuffer (
buf) is interpreted according to these strides (strides define how many bytes each array element, row, column, etc. occupy in memory).formats, names, titles, aligned, byteorderIf
dtypeisNone, these arguments are passed tonumpy.format_parserto construct a dtype. See that function for detailed documentation.copy: bool, optionalWhether to copy the input object (True), or to use a reference instead. This option only applies when the input is an ndarray or recarray. Defaults to True.
Returns
: np.recarrayRecord array created from the specified object.
Notes
If obj is None, then call the recarray constructor. If obj is a string, then call the fromstring constructor. If obj is a list or a tuple, then if the first object is an ndarray, call fromarrays, otherwise call fromrecords. If obj is a recarray, then make a copy of the data in the recarray (if copy=True) and use the new formats, names, and titles. If obj is a file, then call fromfile. Finally, if obj is an ndarray, then return obj.view(recarray), making a copy of the data if copy=True.
Examples
a = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) a✓
np.rec.array(a)
✓b = [(1, 1), (2, 4), (3, 9)] c = np.rec.array(b, formats = ['i2', 'f2'], names = ('x', 'y')) c✓
c.x
✓c.y
✗r = np.rec.array(['abc','def'], names=['col1','col2']) print(r.col1)✓
r.col1
✓r.col2
✓Aliases
-
numpy.rec.array