Numpy的dtype官方文档

2018-10-30  本文已影响0人  麒麟楚庄王

Init signature:np.dtype(self,/,*args,**kwargs)

Docstring:

dtype(obj, align=False, copy=False)

功能

A numpy array is homogeneous, and contains elements described by a

dtype object. A dtype object can be constructed from different

combinations of fundamental numeric types.

参数说明

obj

    Object to be converted to a data type object.

align : bool, optional

    Add padding to the fields to match what a C compiler would output

    for a similar C-struct. Can be ``True`` only if `obj` is a dictionary

    or a comma-separated string. If a struct dtype is being created,

    this also sets a sticky alignment flag ``isalignedstruct``.

copy : bool, optional

    Make a new copy of the data-type object. If ``False``, the result

    may just be a reference to a built-in data-type object.

相关属性

result_type

使用举例

Using array-scalar type:

>>> np.dtype(np.int16)dtype('int16')

Structured type, one field name 'f1', containing int16:

>>> np.dtype([('f1', np.int16)])dtype([('f1', '>> np.dtype([('f1', [('f1', np.int16)])])dtype([('f1', [('f1', '>> np.dtype([('f1', np.uint), ('f2', np.int32)])dtype([('f1', '>> np.dtype([('a','f8'),('b','S10')])dtype([('a', '>> np.dtype("i4, (2,3)f8")dtype([('f0', '>> np.dtype([('hello',(int,3)),('world',np.void,10)])dtype([('hello', '>> np.dtype((np.int16, {'x':(np.int8,0), 'y':(np.int8,1)}))dtype(('>> np.dtype({'names':['gender','age'], 'formats':['S1',np.uint8]})dtype([('gender', '|S1'), ('age', '|u1')])Offsets in bytes, here 0 and 25:>>> np.dtype({'surname':('S25',0),'age':(np.uint8,25)})dtype([('surname', '|S25'), ('age', '|u1')])File:c:\programdata\anaconda3\lib\site-packages\numpy\__init__.pyType:type

上一篇 下一篇

猜你喜欢

热点阅读