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).
Input object. See Notes for details on how various input types are treated.
Valid dtype for array.
Shape of each array.
Position in the file or buffer to start reading from.
Buffer (buf) is interpreted according to these strides (strides define how many bytes each array element, row, column, etc. occupy in memory).
If dtype
is None
, these arguments are passed to numpy.format_parser to construct a dtype. See that function for detailed documentation.
Whether 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.
Record 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 array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
>>> np.rec.array(a) rec.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=int64)
>>> b = [(1, 1), (2, 4), (3, 9)] >>> c = np.rec.array(b, formats = ['i2', 'f2'], names = ('x', 'y')) >>> c rec.array([(1, 1.), (2, 4.), (3, 9.)], dtype=[('x', '<i2'), ('y', '<f2')])
>>> c.x array([1, 2, 3], dtype=int16)
>>> c.y array([1., 4., 9.], dtype=float16)
>>> r = np.rec.array(['abc','def'], names=['col1','col2']) >>> print(r.col1) abc
>>> r.col1 array('abc', dtype='<U3')
>>> r.col2 array('def', dtype='<U3')
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4