数据类型及数组创建
常量
-
空值
print(np.nan) # nan print(np.NAN) # nan print(np.NaN) # nan
numpy中 nan = NaN = NAN 表达的含义一样,字面意思为Not a Number。
np.nan is np.NaN is np.NAN #地址相同 #TRUE None == None #True np.nan == np.nan #nan不同于None不能用 == 进行比较,可以理解为数学上无法表示的无理数 #False print(type(np.nan)) #<class 'float'> print(type(np.NAN)) #<class 'float'> print(type(np.NaN)) #<class 'float'> print(type(None)) #<class 'NoneType'>
由上面的给出的结果可以知道numpy中 nan 与 None 数据类型是有明显的差别的,但它们的逻辑意义几乎一致。
nan 空值 inf 无穷大 pi 圆周率 e 自然常数
数据类型
- numpy常见基本类型
类型 | 备注 | 说明 |
---|---|---|
bool_ = bool8 | 8位 | 整型 |
int8 = byte | 8位 | 整型 |
int16 = short | 16位 | |
int32 = intc | 32位 | |
int_ = int64 = long = int0 = intp | 64位 | 整型 |
uint8 = ubyte | 8位 | 无符号整型 |
uint16 = ushort | 16位 | 无符号整型 |
uint32 = uintc | 32位 | 无符号整型 |
uint64 = uintp = uint0 = uint | 64位 | 无符号整型 |
float16 = half | 16位 | 浮点型 |
float32 = single | 32位 | 浮点型 |
float_ = float64 = double | 64位 | 浮点型 |
str = unicode = str0 = unicode | Unicode 字符串 | |
datetime64 | 日期时间类型 | |
timedelta64 | 表示两个时间之间的间隔 |
-
创建数据类型
numpy 的数据类型实