numpy 1.22.4 Pypi GitHub Homepage
Other Docs
ParametersBackRef
dtype(dtype, 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.

Parameters

dtype :

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 :None:None:`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.

Create a data type object.

See Also

result_type

Examples

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', '<i2')])

Structured type, one field named 'f1', in itself containing a structured type with one field:

>>> np.dtype([('f1', [('f1', np.int16)])])
dtype([('f1', [('f1', '<i2')])])

Structured type, two fields: the first field contains an unsigned int, the second an int32:

>>> np.dtype([('f1', np.uint64), ('f2', np.int32)])
dtype([('f1', '<u8'), ('f2', '<i4')])

Using array-protocol type strings:

>>> np.dtype([('a','f8'),('b','S10')])
dtype([('a', '<f8'), ('b', 'S10')])

Using comma-separated field formats. The shape is (2,3):

>>> np.dtype("i4, (2,3)f8")
dtype([('f0', '<i4'), ('f1', '<f8', (2, 3))])

Using tuples. int is a fixed type, 3 the field's shape. void is a flexible type, here of size 10:

>>> np.dtype([('hello',(np.int64,3)),('world',np.void,10)])
dtype([('hello', '<i8', (3,)), ('world', 'V10')])

Subdivide int16 into 2 int8 's, called x and y. 0 and 1 are the offsets in bytes:

>>> np.dtype((np.int16, {'x':(np.int8,0), 'y':(np.int8,1)}))
dtype((numpy.int16, [('x', 'i1'), ('y', 'i1')]))

Using dictionaries. Two fields named 'gender' and 'age':

>>> 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')])
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

numpy

56 Elements
numpy.common_type
numpy.ascontiguousarray
numpy.issubdtype
numpy.asarray
numpy.nanstd
numpy.rec.array
numpy.memmap
numpy.mean
numpy.lib.format.descr_to_dtype
numpy.nanmean
numpy.rec.fromstring
numpy.find_common_type
numpy.result_type
numpy.nancumsum
numpy.core._multiarray_umath.min_scalar_type
numpy.geomspace
numpy.ma.core.make_mask
numpy.rec.fromrecords
numpy.promote_types
numpy.fromstring
numpy.ma.core._recursive_fill_value
numpy.ma.core.MaskedArray
numpy.lib.format.dtype_to_descr
numpy.logspace
numpy.std
numpy.lib._iotools.easy_dtype
numpy.array
numpy.core.multiarray.scalar
numpy.ma.core.array
numpy.rec.fromarrays
numpy.linspace
numpy.arange
numpy.lib._iotools.StringConverter
numpy.fromregex
numpy.mintypecode
numpy.fromfunction
numpy.core._multiarray_umath.can_cast
numpy.core._multiarray_umath.result_type
numpy.ma.core.MaskedArray.view
numpy.lib._iotools.StringConverter.update
numpy.lib.npyio.recfromcsv
numpy.ma.extras.masked_all
numpy.min_scalar_type
numpy.maximum_sctype
numpy.ndarray
numpy.asfarray
numpy.typename
numpy.format_parser
numpy.lib.npyio.recfromtxt
numpy.can_cast
numpy.ma.core.choose
numpy.lib.format.open_memmap
numpy.rec.fromfile
numpy.recarray
numpy.ma.core.make_mask_none
numpy.cumsum

pandas

pandas.core.dtypes.cast.maybe_infer_dtype_type
pandas.core.generic.NDFrame.convert_dtypes
pandas.core.dtypes.common.is_timedelta64_ns_dtype
pandas.core.dtypes.missing.na_value_for_dtype
pandas.core.arrays.sparse.array.SparseArray.astype
pandas.core.construction.array
pandas.core.dtypes.dtypes.PandasDtype

networkx

networkx.convert_matrix.to_numpy_array

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /numpy/__init__.py#None
type: <class 'numpy._DTypeMeta'>
Commit: