Numpy Scalars(标量)

xiaoxiao2021-02-28  98

在Python中只有一个整型和和一个浮点型的数据类型,而在NumPy中则由24种不同的数据类型.

import numpy as np np.float32(-1.1) == np.float64(-1.1)

Booleans(布尔型)

TypeRemarksCharacter codebool_compatible: Python bool?’bool88 bits

Integers(整型)

类型注释字符串码bytecompatible: C charb’shortcompatible: C shorth’intccompatible: C inti’int_compatible: Python intl’longlongcompatible: C long longq’intplarge enough to fit a pointerp’int88 bitsint1616 bitsint3232 bitsint6464 bits

Unsigned integers(无符号整型)

类型标注字符串码ubytecompatible: C unsigned charB’ushortcompatible: C unsigned shortH’uintccompatible: C unsigned intI’uintcompatible: Python intL’ulonglongcompatible: C long longQ’uintplarge enough to fit a pointerP’uint88 bitsuint1616 bitsuint3232 bitsuint6464 bits

Floating-point numbers(浮点型)

类型标注字符串码halfe’singlecompatible: C floatf’doublecompatible: C doublefloat_compatible: Python floatd’longfloatcompatible: C long floatg’float1616 bitsfloat3232 bitsfloat6464 bitsfloat9696 bits, platform?float128128 bits, platform?

Complex floating-point numbers(复杂浮点型)

类型标注字符码csingleF’complex_compatible: Python complexD’clongfloatG’complex64two 32-bit floatscomplex128two 64-bit floatscomplex192two 96-bit floats, platform?complex256two 128-bit floats, platform?

常用数据类型

类型字符码booleanb’(signed) integeri’unsigned integeru’floating-pointfcomplex-floating pointctimedeltamdatetimeM(Python) objectsO(byte-)stringS, aUnicodeUraw data (void)V’

例子:

>>> dt = np.dtype('i4') # 32-bit signed integer >>> dt = np.dtype('f8') # 64-bit floating-point number >>> dt = np.dtype('c16') # 128-bit complex floating-point number >>> dt = np.dtype('a25') # 25-character string

参考文献: https://docs.scipy.org/doc/numpy/reference/arrays.scalars.html#arrays-scalars-built-in

转载请注明原文地址: https://www.6miu.com/read-32638.html

最新回复(0)