寒冰射手攻略,麦包包 正品 女包,合金装备2
简介
Python语言中只定义了特定数据类的一种类型(比如只有一种整数类型,一种浮点类型等)。在不需要关注计算机中数据表示方式的普通应用程序中,这样做很方便。但是,对于科学计算来说,我们需要更加精确的控制类型。
在NumPy中,引入了24种新的Python scalar类型用于更加准确的描述数据。这些类型都是可以直接在NumPy中的数组中使用的,所以也叫Array scalar类型。
本文将会详细讲解这24种scalar类型。
scalar类型的层次结构
先看一个张图,看下scalar类型的层次结构:
上面实线方框括起来的,就是scalar类型。这些标量类型,都可以通过
np.type
来访问,比如:
In [130]: np.intcOut[130]: numpy.int32
细心的小伙伴可能要问了,这不对呀,实线方框括起来的只有22中类型,还有两个类型是什么?
还有两个是代表整数指针的
intp
和uintp
。注意,array scalars 类型是不可变的。
我们可以isinstance来对这些数组标量来进行层次结构的检测。
例如,如果val是数组标量对象,则isinstance(val,np.generic)将返回True。如果val是复数值类型,则isinstance(val,np.complexfloating)将返回True。
内置Scalar类型
我们用下面的表来展示内置的Scalar类型和与他们相对应的C类型或者Python类型。最后一列的字符代码是类型的字符表示,在有些情况比如构建dtype中会使用到。
boolean 类型 描述 字符代码
bool_
compatible: Python boolbool8
8 bitsIntegers 类型 描述 字符代码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 bitsint16
16 bitsint32
32 bitsint64
64 bitsUnsigned 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 bitsuint16
16 bitsuint32
32 bitsuint64
64 bitsFloating-point numbers 类型 描述 字符代码half
'e'
single
compatible: C float'f'
double
compatible: C doublefloat_
compatible: Python float'd'
longfloat
compatible: C long float'g'
float16
16 bitsfloat32
本文地址:http://www.reviewcode.cn/youxikaifa/203925.html 转载请注明出处!
伍佰目录声明:本站部分文章来源于网络,版权属于原作者所有。如有转载或引用文章/图片涉及版权问题,请联系我们处理.我们将在第一时间删除! 联系邮箱:[email protected]