Data type dtype usage in tensorflow

Time:2021-12-3

In tensorflow, there are mainly the following data types (dtypes), which can be used without TF in the old version.

signed int

Tf.int8: 8-bit integer.

Tf.int16: 16 bit integer.

Tf.int32: 32-bit integer.

Tf.int64: 64 bit integer.

unsigned int

Tf.uint8: 8-bit unsigned integer.

Tf.uint16: 16 bit unsigned integer.

float

Tf.float16: 16 bit floating point number.

Tf.float32: 32-bit floating point number.

Tf.float64: 64 bit floating point number.

Tf.double: equivalent to tf.float64.

String type

Tf.string: string.

Boolean

Tf.bool: Boolean.

Plural form

Tf.complex64: 64 bit complex.

Tf.complex128: 128 bit complex.

Supplement: dtype summary of data type objects of tensorflow and numpy

1. Dtyte and astype

Dtype: view data types

Astype: converting data types

Data type dtype usage in tensorflow

2. Tensorlow data type object dtype

name describe
tf.float16 16 bit half precision floating point
tf.float32 32-bit single precision floating point
tf.float64 64 bit double precision floating point
tf.bfloat16 16 bit truncated floating point
tf.complex64 64 bit single precision complex
tf.complex128 128 bit double precision complex
tf.int8 8-bit signed integer
tf.uint8 8-bit unsigned integer
tf.uint16 16 bit unsigned integer
tf.int16 16 bit signed integer
tf.int32 32-bit signed integer
tf.int64 64 bit signed integer
tf.bool Boolean value
tf.string character string
tf.qint8 Quantized 8-bit signed integer
tf.quint8 Quantized 8-bit unsigned integer
tf.qint16 Quantized 16 bit signed integer
tf.quint16 Quantized 16 bit unsigned integer
tf.qint32 Quantized 32-bit signed integer

tf.as_ The dtype () function converts numpy type and string type names to dtype objects.

3. Numpy data type object dtype

name describe
np.bool_ Boolean data type
np.int_ Default integer type
np.intc Like the int type of C, it is usually int32 or int 64
np.intp The integer type used for indexing, usually int32 or Int64
np.int8 8-bit integer, i.e. 1 byte (- 128 to 127)
np.int16 16 bit integer (- 32768 to 32767)
np.int32 32-bit integer (- 2147483648 to 2147483647)
np.int64 64 bit integer (- 9223372036854775808 to 9223372036854775807)
np.uint8 8-bit unsigned integer (0 to 255)
np.uint16 16 bit unsigned integer (0 to 65535)
np.uint32 32-bit unsigned integer (0 to 4294967295)
np.uint64 64 bit unsigned integer (0 to 18446744073709551615)
np.float_ Float64 is short for 64 bit double precision floating point number
np.float16 16 bit semi precision floating-point number, including 1 symbol bit, 5 finger digits and 10 trailing digits
np.float32 32-bit single precision floating-point number, including 1 symbol bit, 8 finger digits and 23 trailing digits
np.float64 64 bit double precision floating-point number, including 1 symbol bit, 11 finger digits and 52 trailing digits
np.complex_ Complex128 is short for 128 bit complex
np.complex64 Complex number, representing double 32-bit floating-point number (real part and imaginary part)
np.complex128 A complex number that represents a double 64 bit floating-point number (real part and imaginary part)

The above is my personal experience. I hope I can give you a reference, and I hope you can support developepper.