w3resource

NumPy: Data type

Data type

A data type object describes how the bytes in the fixed-size block of memory corresponding to an array item should be interpreted. It describes the following aspects of the data:

  • Type of the data (integer, float, Python object, etc.)
  • Size of the data (number of bytes is in e.g. the integer)
  • Byte order of the data (little-endian or big-endian)
  • If the data type is structured, an aggregate of other data types,
    • Type of the data (integer, float, Python object, etc.)
    • Size of the data (how many bytes is in e.g. the integer)
    • Byte order of the data (little-endian or big-endian)
    • If the data type is structured, an aggregate of other data types, (e.g., describing an array item consisting of an integer and a float),
  • If the data type is a sub-array, what is its shape and data type.
Data type routines
Name Description Syntax
can_cast() Returns True if cast between data types can occur according to the casting rule numpy.can_cast(from_, to, casting='safe')
promote_types() Returns the data type with the smallest size and smallest scalar kind to which both type1 and type2 may be safely cast. numpy.promote_types(type1, type2)
min_scalar_type() Returns the data type with the smallest size and smallest scalar kind which can hold its value. numpy.min_scalar_type(a)
result_type() Returns the type that results from applying the NumPy type promotion rules to the arguments. numpy.result_type(*arrays_and_dtypes)
common_type() Return a scalar type which is common to the input arrays. numpy.common_type(*arrays)
obj2sctype() Return the scalar dtype or NumPy equivalent of Python type of an object. numpy.obj2sctype(rep, default=None)
Creating data types
Name Description Syntax
dtype Create a data type object. class numpy.dtype(obj, align=False, copy=False)
format_parser Class to convert formats, names, titles description to a dtype. class numpy.format_parser(formats, names, titles, aligned=False, byteorder=None)
Data type information
Name Description Syntax
finfo() Machine limits for integer types. class numpy.finfo(dtype)
iinfo() Machine limits for integer types. class numpy.iinfo(type)
MachAr() Diagnosing machine parameters. class numpy.MachAr(float_conv=<class 'float'>, int_conv=<class 'int'>, float_to_float=<class 'float'>, float_to_str=<function MachAr.<lambda>>, title='Python floating point number')
Data type testing
Name Description Syntax
issctype() Determines whether the given object represents a scalar data-type. numpy.iinfo(type)
issubdtype() Returns True if first argument is a typecode lower/equal in type hierarchy. numpy.issubdtype(arg1, arg2)
issubsctype() Determine if the first argument is a subclass of the second argument. numpy.issubsctype(arg1, arg2)
issubclass_() Determine if a class is a subclass of a second class. numpy.issubclass_(arg1, arg2)
find_common_type() Determine common type following standard coercion rules. numpy.find_common_type(array_types, scalar_types)
Miscellaneous
Name Description Syntax
typename() Return a description for the given data type code. numpy.typename(char)
sctype2char() Return the string representation of a scalar dtype. numpy.sctype2char(sctype)
mintypecode() Return the character for the minimum-size type to which given types can be safely cast. numpy.mintypecode(typechars, typeset='GDFgdf', default='d')

Previous: Convenience class chararray()
Next: Data type can_cast()



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/numpy/data-type-routines/index.php