Numpy Scalars(标量)

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

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

这里写图片描述

Booleans(布尔型)

TypeRemarksCharacter code
bool_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 bits
int1616 bits
int3232 bits
int6464 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 bits
uint1616 bits
uint3232 bits
uint6464 bits

Floating-point numbers(浮点型)

类型标注字符串码
halfe’
singlecompatible: C floatf’
doublecompatible: C double
float_compatible: Python floatd’
longfloatcompatible: C long floatg’
float1616 bits
float3232 bits
float6464 bits
float9696 bits, platform?
float128128 bits, platform?

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

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

常用数据类型

类型字符码
booleanb’
(signed) integeri’
unsigned integeru’
floating-pointf
complex-floating pointc
timedeltam
datetimeM
(Python) objectsO
(byte-)stringS, a
UnicodeU
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

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值