Construct an ndarray that allows field access using attributes.
Arrays may have a data-types containing fields, analogous to columns in a spread sheet. An example is [(x, int), (y, float)], where each entry in the array is a pair of (int, float). Normally, these attributes are accessed using dictionary lookups such as arr['x'] and arr['y']. Record arrays allow the fields to be accessed as members of the array, using arr.x and arr.y.
Parameters : | shape : tuple
dtype : data-type, optional
formats : list of data-types, optional
names : tuple of str, optional
buf : buffer, optional
|
---|---|
Returns : | rec : recarray
|
Other Parameters: | |
titles : tuple of str, optional
byteorder : {‘<’, ‘>’, ‘=’}, optional
aligned : bool, optional
strides : tuple of ints, optional
offset : int, optional
order : {‘C’, ‘F’}, optional
|
See also
Notes
This constructor can be compared to empty: it creates a new record array but does not fill it with data. To create a record array from data, use one of the following methods:
Examples
Create an array with two fields, x and y:
>>> x = np.array([(1.0, 2), (3.0, 4)], dtype=[('x', float), ('y', int)])
>>> x
array([(1.0, 2), (3.0, 4)],
dtype=[('x', '<f8'), ('y', '<i4')])
>>> x['x']
array([ 1., 3.])
View the array as a record array:
>>> x = x.view(np.recarray)
>>> x.x
array([ 1., 3.])
>>> x.y
array([2, 4])
Create a new, empty record array:
>>> np.recarray((2,),
... dtype=[('x', int), ('y', float), ('z', int)])
rec.array([(-1073741821, 1.2249118382103472e-301, 24547520),
(3471280, 1.2134086255804012e-316, 0)],
dtype=[('x', '<i4'), ('y', '<f8'), ('z', '<i4')])
Methods
all | |
any | |
argmax | |
argmin | |
argsort | |
astype | |
byteswap | |
choose | |
clip | |
compress | |
conj() | Return the complex conjugate, element-wise. |
conjugate() | Return the complex conjugate, element-wise. |
copy | |
cumprod | |
cumsum | |
diagonal | |
dot | |
dump | |
dumps | |
field | |
fill | |
flatten | |
getfield | |
item | |
itemset | |
max | |
mean | |
min | |
newbyteorder | |
nonzero | |
prod | |
ptp | |
put | |
ravel | |
repeat | |
reshape | |
resize | |
round | |
searchsorted | |
setasflat | |
setfield | |
setflags | |
sort | |
squeeze | |
std | |
sum | |
swapaxes | |
take | |
tofile | |
tolist | |
tostring | |
trace | |
transpose | |
var | |
view |