在Python中只有一个整型和和一个浮点型的数据类型,而在NumPy中则由24种不同的数据类型.
import numpy as np
np.float32(-1.1) == np.float64(-1.1)
Booleans(布尔型)
Type | Remarks | Character code |
---|
bool_ | compatible: Python bool | ?’ |
bool8 | 8 bits | |
Integers(整型)
类型 | 注释 | 字符串码 |
---|
byte | compatible: C char | b’ |
short | compatible: C short | h’ |
intc | compatible: C int | i’ |
int_ | compatible: Python int | l’ |
longlong | compatible: C long long | q’ |
intp | large enough to fit a pointer | p’ |
int8 | 8 bits | |
int16 | 16 bits | |
int32 | 32 bits | |
int64 | 64 bits | |
Unsigned integers(无符号整型)
类型 | 标注 | 字符串码 |
---|
ubyte | compatible: C unsigned char | B’ |
ushort | compatible: C unsigned short | H’ |
uintc | compatible: C unsigned int | I’ |
uint | compatible: Python int | L’ |
ulonglong | compatible: C long long | Q’ |
uintp | large enough to fit a pointer | P’ |
uint8 | 8 bits | |
uint16 | 16 bits | |
uint32 | 32 bits | |
uint64 | 64 bits | |
Floating-point numbers(浮点型)
类型 | 标注 | 字符串码 |
---|
half | | e’ |
single | compatible: C float | f’ |
double | compatible: C double | |
float_ | compatible: Python float | d’ |
longfloat | compatible: C long float | g’ |
float16 | 16 bits | |
float32 | 32 bits | |
float64 | 64 bits | |
float96 | 96 bits, platform? | |
float128 | 128 bits, platform? | |
Complex floating-point numbers(复杂浮点型)
类型 | 标注 | 字符码 |
---|
csingle | | F’ |
complex_ | compatible: Python complex | D’ |
clongfloat | | G’ |
complex64 | two 32-bit floats | |
complex128 | two 64-bit floats | |
complex192 | two 96-bit floats, platform? | |
complex256 | two 128-bit floats, platform? | |
常用数据类型
类型 | 字符码 |
---|
boolean | b’ |
(signed) integer | i’ |
unsigned integer | u’ |
floating-point | f |
complex-floating point | c |
timedelta | m |
datetime | M |
(Python) objects | O |
(byte-)string | S, a |
Unicode | U |
raw 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