Тип данных uint8 python

Data Types¶

A conforming implementation of the array API standard must provide and support the following data types.

bool¶

int8¶

An 8-bit signed integer whose values exist on the interval [-128, +127] .

int16¶

A 16-bit signed integer whose values exist on the interval [−32,767, +32,767] .

int32¶

A 32-bit signed integer whose values exist on the interval [−2,147,483,647, +2,147,483,647] .

int64¶

A 64-bit signed integer whose values exist on the interval [−9,223,372,036,854,775,807, +9,223,372,036,854,775,807] .

uint8¶

An 8-bit unsigned integer whose values exist on the interval [0, +255] .

uint16¶

A 16-bit unsigned integer whose values exist on the interval [0, +65,535] .

uint32¶

A 32-bit unsigned integer whose values exist on the interval [0, +4,294,967,295] .

uint64¶

A 64-bit unsigned integer whose values exist on the interval [0, +18,446,744,073,709,551,615] .

float32¶

IEEE 754 single-precision (32-bit) binary floating-point number (see IEEE 754-2019).

float64¶

IEEE 754 double-precision (64-bit) binary floating-point number (see IEEE 754-2019).

complex64¶

Single-precision (64-bit) complex floating-point number whose real and imaginary components must be IEEE 754 single-precision (32-bit) binary floating-point numbers (see IEEE 754-2019).

complex128¶

Double-precision (128-bit) complex floating-point number whose real and imaginary components must be IEEE 754 double-precision (64-bit) binary floating-point numbers (see IEEE 754-2019).

IEEE 754-2019 requires support for subnormal (a.k.a., denormal) numbers, which are useful for supporting gradual underflow. However, hardware support for subnormal numbers is not universal, and many platforms (e.g., accelerators) and compilers support toggling denormals-are-zero (DAZ) and/or flush-to-zero (FTZ) behavior to increase performance and to guard against timing attacks.

Accordingly, subnormal behavior is left unspecified and, thus, implementation-defined. Conforming implementations may vary in their support for subnormal numbers.

A conforming implementation of the array API standard may provide and support additional data types beyond those described in this specification.

Data Type Objects¶

Data types (“dtypes”) are objects which are used as dtype specifiers in functions and methods (e.g., zeros((2, 3), dtype=float32) ).

A conforming implementation may add additional methods or attributes to data type objects beyond those described in this specification.

Implementations may provide other ways to specify data types (e.g., zeros((2, 3), dtype=’f4′) ) which are not described in this specification; however, in order to ensure portability, array library consumers are recommended to use data type objects as provided by specification conforming array libraries.

A conforming implementation of the array API standard must provide and support data type objects having the following attributes and methods.

Methods¶

Computes the truth value of self == other in order to test for data type object equality.

Default Data Types¶

A conforming implementation of the array API standard must define the following default data types.

  • a default real-valued floating-point data type (either float32 or float64 ).
  • a default complex floating-point data type (either complex64 or complex128 ).
  • a default integer data type (either int32 or int64 ).
  • a default array index data type (either int32 or int64 ).

The default real-valued floating-point and complex floating-point data types must be the same across platforms.

The default complex floating-point point data type should match the default real-valued floating-point data type. For example, if the default real-valued floating-point data type is float32 , the default complex floating-point data type must be complex64 . If the default real-valued floating-point data type is float64 , the default complex floating-point data type must be complex128 .

The default integer data type should be the same across platforms, but the default may vary depending on whether Python is 32-bit or 64-bit.

The default array index data type may be int32 on 32-bit platforms, but the default should be int64 otherwise.

Note that it is possible that a library supports multiple devices, with not all those device types supporting the same data types. In this case, the default integer or floating-point data types may vary with device. If that is the case, the library should clearly warn about this in its documentation.

The default data types should be clearly defined in a conforming library’s documentation.

Data Type Categories¶

For the purpose of organizing functions within this specification, the following data type categories are defined.

Conforming libraries are not required to organize data types according to these categories. These categories are only intended for use within this specification.

Numeric Data Types¶

int8 , int16 , int32 , int64 , uint8 , uint16 , uint32 , uint64 , float32 , float64 , complex64 , and complex128 .

Real-valued Data Types¶

int8 , int16 , int32 , int64 , uint8 , uint16 , uint32 , uint64 , float32 , and float64 .

Integer Data Types¶

int8 , int16 , int32 , int64 , uint8 , uint16 , uint32 , and uint64 .

Floating-point Data Types¶

float32 , float64 , complex64 , and complex128 .

Real-valued Floating-point Data Types¶

Complex Floating-point Data Types¶

Источник

Data type objects ( dtype )#

A data type object (an instance of numpy.dtype class) 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:

  1. Type of the data (integer, float, Python object, etc.)
  2. Size of the data (how many bytes is in e.g. the integer)
  3. Byte order of the data ( little-endian or big-endian )
  4. If the data type is structured data type , an aggregate of other data types, (e.g., describing an array item consisting of an integer and a float),
    1. what are the names of the “ fields ” of the structure, by which they can be accessed ,
    2. what is the data-type of each field , and
    3. which part of the memory block each field takes.

    To describe the type of scalar data, there are several built-in scalar types in NumPy for various precision of integers, floating-point numbers, etc. An item extracted from an array, e.g., by indexing, will be a Python object whose type is the scalar type associated with the data type of the array.

    Note that the scalar types are not dtype objects, even though they can be used in place of one whenever a data type specification is needed in NumPy.

    Structured data types are formed by creating a data type whose field contain other data types. Each field has a name by which it can be accessed . The parent data type should be of sufficient size to contain all its fields; the parent is nearly always based on the void type which allows an arbitrary item size. Structured data types may also contain nested structured sub-array data types in their fields.

    Finally, a data type can describe items that are themselves arrays of items of another data type. These sub-arrays must, however, be of a fixed size.

    If an array is created using a data-type describing a sub-array, the dimensions of the sub-array are appended to the shape of the array when the array is created. Sub-arrays in a field of a structured type behave differently, see Field access .

    Sub-arrays always have a C-contiguous memory layout.

    A simple data type containing a 32-bit big-endian integer: (see Specifying and constructing data types for details on construction)

    >>> dt = np.dtype('>i4') >>> dt.byteorder '>' >>> dt.itemsize 4 >>> dt.name 'int32' >>> dt.type is np.int32 True 

    The corresponding array scalar type is int32 .

    A structured data type containing a 16-character string (in field ‘name’) and a sub-array of two 64-bit floating-point number (in field ‘grades’):

    >>> dt = np.dtype([('name', np.unicode_, 16), ('grades', np.float64, (2,))]) >>> dt['name'] dtype(' >>> dt['grades'] dtype((' 

    Items of an array of this data type are wrapped in an array scalar type that also has two fields:

    >>> x = np.array([(‘Sarah’, (8.0, 7.0)), (‘John’, (6.0, 7.0))], dtype=dt) >>> x[1] (‘John’, [6., 7.]) >>> x[1][‘grades’] array([6., 7.]) >>> type(x[1]) >>> type(x[1][‘grades’])

    Specifying and constructing data types#

    Whenever a data-type is required in a NumPy function or method, either a dtype object or something that can be converted to one can be supplied. Such conversions are done by the dtype constructor:

    Create a data type object.

    What can be converted to a data-type object is described below:

    The 24 built-in array scalar type objects all convert to an associated data-type object. This is true for their sub-classes as well.

    Note that not all data-type information can be supplied with a type-object: for example, flexible data-types have a default itemsize of 0, and require an explicitly given size to be useful.

    >>> dt = np.dtype(np.int32) # 32-bit integer >>> dt = np.dtype(np.complex128) # 128-bit complex floating-point number 

    The generic hierarchical type objects convert to corresponding type objects according to the associations:

    Источник

    Читайте также:  Calling functions in python main
Оцените статью