开发手册 欢迎您!
软件开发者资料库

Python numpy.core.records.fromarrays函数方法的使用

NumPy(Numerical Python的缩写)是一个开源的Python科学计算库。使用NumPy,就可以很自然地使用数组和矩阵。NumPy包含很多实用的数学函数,涵盖线性代数运算、傅里叶变换和随机数生成等功能。本文主要介绍一下NumPy中core.records.fromarrays方法的使用。

numpy.core.records.fromarrays

numpy.core.records.fromarrays(arrayList, dtype=None, shape=None, formats=None, names=None, titles=None, aligned=False, byteorder=None)[source]

从(flat)数组列表创建记录数组

参数 :

arrayListlisttuple

类数组对象的列表(例如,列表,元组和ndarray)。

dtypedata-type, 可选

所有数组的有效dtype

shapeint 或 ints的tuple, 可选

所得数组的Shape。 如果未提供,则从arrayList [0]推断。

formats, names, titles, aligned, byteorder

如果dtypeNone

则将这些参数传递给numpy.format_parser以构造dtype。 

有关详细文档,请参见该功能。

返回值 :

np.recarray

记录由给定的arrayList列组成的数组。

例子

>>> x1=np.array([1,2,3,4])>>> x2=np.array(['a','dd','xyz','12'])>>> x3=np.array([1.1,2,3,4])>>> r = np.core.records.fromarrays([x1,x2,x3],names='a,b,c')>>> print(r[1])(2, 'dd', 2.0) # may vary>>> x1[1]=34>>> r.aarray([1, 2, 3, 4])
>>> x1 = np.array([1, 2, 3, 4])>>> x2 = np.array(['a', 'dd', 'xyz', '12'])>>> x3 = np.array([1.1, 2, 3,4])>>> r = np.core.records.fromarrays(...     [x1, x2, x3],...     dtype=np.dtype([('a', np.int32), ('b', 'S3'), ('c', np.float32)]))>>> rrec.array([(1, b'a', 1.1), (2, b'dd', 2. ), (3, b'xyz', 3. ),           (4, b'12', 4. )],          dtype=[('a', '
                    
})();