numpy.
recarray
构造允许使用属性访问字段的ndarray。
数组可以具有包含字段的数据类型,类似于电子表格中的列。一个例子是 [(x, int), (y, float)] ,其中数组中的每个条目是一对 (int, float) . 通常,使用字典查找访问这些属性,例如 arr['x'] 和 arr['y'] . 记录数组允许作为数组成员访问字段,使用 arr.x 和 arr.y .
[(x, int), (y, float)]
(int, float)
arr['x']
arr['y']
arr.x
arr.y
输出数组的形状。
所需的数据类型。默认情况下,数据类型由 formats , names , titles , aligned 和 byteorder .
包含不同列的数据类型的列表,例如 ['i4', 'f8', 'i4'] . formats 做 not 支持直接使用类型的新约定,即 (int, float, int) . 注意 formats 必须是列表,而不是元组。鉴于 formats 有点有限,我们建议具体说明 dtype 相反。
['i4', 'f8', 'i4']
(int, float, int)
dtype
每列的名称,例如 ('x', 'y', 'z') .
('x', 'y', 'z')
默认情况下,将创建具有给定形状和数据类型的新数组。如果 buf 是一个公开缓冲区接口的对象,数组将使用现有缓冲区中的内存。在这种情况下, offset 和 strides 关键字可用。
给定形状和类型的空数组。
列名的别名。例如,如果 names 是 ('x', 'y', 'z') 和 titles 是 ('x_coordinate', 'y_coordinate', 'z_coordinate') 然后 arr['x'] 等于两者 arr.x 和 arr.x_coordinate .
('x_coordinate', 'y_coordinate', 'z_coordinate')
arr.x_coordinate
所有字段的字节顺序。
像C编译器那样对齐内存中的字段。
缓冲区 (buf )根据这些步幅进行解释(步幅定义每个数组元素、行、列等在内存中所占的字节数)。
开始读取缓冲区 (buf )从这个偏移量开始。
行主要(C样式)或列主要(Fortran样式)顺序。
参见
core.records.fromrecords
从数据构造记录数组。
record
的基本数据类型 recarray .
format_parser
根据格式、名称、标题确定数据类型。
笔记
此构造函数可以与 empty :它创建一个新的记录数组,但不填充数据。要从数据创建记录数组,请使用以下方法之一:
empty
创建标准ndarray并将其转换为记录数组,使用 arr.view(np.recarray)
arr.view(np.recarray)
使用 buf 关键字。
使用 np.rec.fromrecords .
实例
创建一个包含两个字段的数组, x 和 y :
x
y
>>> x = np.array([(1.0, 2), (3.0, 4)], dtype=[('x', '<f8'), ('y', '<i8')]) >>> x array([(1., 2), (3., 4)], dtype=[('x', '<f8'), ('y', '<i8')])
>>> x['x'] array([1., 3.])
将数组作为记录数组查看:
>>> x = x.view(np.recarray)
>>> x.x array([1., 3.])
>>> x.y array([2, 4])
创建新的空记录数组:
>>> 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')])
T
换位数组。
base
如果内存来自其他对象,则为基对象。
ctypes
简化数组与CTypes模块交互的对象。
data
python缓冲区对象指向数组数据的开头。
数组元素的数据类型。
flags
有关数组内存布局的信息。
flat
数组上的一维迭代器。
imag
数组的虚部。
itemsize
一个数组元素的长度(字节)。
nbytes
数组元素消耗的总字节数。
ndim
数组维数。
real
数组的实际部分。
shape
数组维度的元组。
size
数组中的元素数。
strides
遍历数组时要在每个维度中单步执行的字节元组。
方法
all \ [axis, out, keepdims, where] )
all
如果所有元素的计算结果都为true,则返回true。
any \ [axis, out, keepdims, where] )
any
如果的任何元素 a 计算为真。
argmax \ [axis, out] )
argmax
返回给定轴上最大值的索引。
argmin \ [axis, out] )
argmin
返回沿给定轴的最小值的索引。
argpartition (KTH) [, axis, kind, order] )
argpartition
返回将对此数组进行分区的索引。
argsort \ [axis, kind, order] )
argsort
返回将对此数组进行排序的索引。
astype (dType) [, order, casting, subok, copy] )
astype
数组的副本,强制转换为指定类型。
byteswap \ [inplace] )
byteswap
交换数组元素的字节
choose [选择] [, out, mode] )
choose
使用索引数组从一组选项中构造新数组。
clip \ [min, max, out] )
clip
返回值限制为的数组 [min, max] .
[min, max]
compress [条件] [, axis, out] )
compress
沿给定轴返回此数组的选定切片。
conj ()
conj
复共轭所有元素。
conjugate ()
conjugate
返回复共轭,按元素排序。
copy \ [order] )
copy
返回数组的副本。
cumprod \ [axis, dtype, out] )
cumprod
返回元素沿给定轴的累积积。
cumsum \ [axis, dtype, out] )
cumsum
返回给定轴上元素的累积和。
diagonal \ [offset, axis1, axis2] )
diagonal
返回指定的对角线。
dot (b) [, out] )
dot
两个数组的点积。
dump \(文件)
dump
将数组的pickle转储到指定的文件。
dumps ()
dumps
以字符串形式返回数组的pickle。
fill 值(值)
fill
用标量值填充数组。
flatten \ [order] )
flatten
返回折叠为一维的数组的副本。
getfield (dType) [, offset] )
getfield
以特定类型返回给定数组的字段。
item * ARGs)
item
将数组的元素复制到标准的python标量并返回它。
itemset * ARGs)
itemset
将标量插入数组(如果可能,将标量转换为数组的dtype)
max \ [axis, out, keepdims, initial, where] )
max
沿给定轴返回最大值。
mean \ [axis, dtype, out, keepdims, where] )
mean
返回沿给定轴的数组元素的平均值。
min \ [axis, out, keepdims, initial, where] )
min
沿给定轴返回最小值。
newbyteorder \ [new_order] )
newbyteorder
以不同的字节顺序返回具有相同数据的数组。
nonzero ()
nonzero
返回非零元素的索引。
partition (KTH) [, axis, kind, order] )
partition
重新排列数组中的元素,使第k个位置的元素值位于排序数组中的位置。
prod \ [axis, dtype, out, keepdims, initial, ...] )
prod
返回数组元素在给定轴上的乘积
ptp \ [axis, out, keepdims] )
ptp
沿给定轴的峰间(最大-最小)值。
put \(索引,值[, mode] )
put
集合 a.flat[n] = values[n] 为了所有 n 在索引中。
a.flat[n] = values[n]
ravel \ [order] )
ravel
返回扁平数组。
repeat [重复] [, axis] )
repeat
重复数组元素。
reshape [形状] [, order] )
reshape
返回包含具有新形状的相同数据的数组。
resize \新的形状 [, refcheck] )
resize
就地更改数组的形状和大小。
round \ [decimals, out] )
round
返回 a 每个元素四舍五入到给定的小数位数。
searchsorted (V) [, side, sorter] )
searchsorted
查找应在a中插入v元素以保持顺序的索引。
setfield \(VAL,数据类型[, offset] )
setfield
将值放入由数据类型定义的字段中的指定位置。
setflags \ [write, align, uic] )
setflags
分别设置数组标志可写、对齐(writebackifcopy和updateifcopy)。
sort \ [axis, kind, order] )
sort
对数组进行就地排序。
squeeze \ [axis] )
squeeze
从中删除长度为1的轴 a .
std \ [axis, dtype, out, ddof, keepdims, where] )
std
返回数组元素沿给定轴的标准偏差。
sum \ [axis, dtype, out, keepdims, initial, where] )
sum
返回给定轴上数组元素的和。
swapaxes \(轴1、轴2)
swapaxes
返回数组的视图 axis1 和 axis2 互换的
take [指数] [, axis, out, mode] )
take
返回由以下元素组成的数组 a 在给定的指数上。
tobytes \ [order] )
tobytes
构造包含数组中原始数据字节的python字节。
tofile (FID) [, sep, format] )
tofile
将数组以文本或二进制形式写入文件(默认)。
tolist ()
tolist
作为数组返回 a.ndim -Python标量的深度嵌套列表。
a.ndim
tostring \ [order] )
tostring
的兼容性别名 tobytes ,行为完全相同。
trace \ [offset, axis1, axis2, dtype, out] )
trace
沿数组的对角线返回和。
transpose * 轴)
transpose
返回转置轴的数组视图。
var \ [axis, dtype, out, ddof, keepdims, where] )
var
返回数组元素沿给定轴的方差。
view \ [dtype] [, type] )
view
具有相同数据的数组的新视图。
field