寒冰射手攻略,麦包包 正品 女包,合金装备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 boolbool88 bitsIntegers 类型 描述 字符代码bytecompatible: C char'b'shortcompatible: C short'h'intccompatible: C int'i'int_compatible: Python int'l'longlongcompatible: C long long'q'intplarge enough to fit a pointer'p'int88 bitsint1616 bitsint3232 bitsint6464 bitsUnsigned integers 类型 描述 字符代码ubytecompatible: C unsigned char'B'ushortcompatible: C unsigned short'H'uintccompatible: C unsigned int'I'uintcompatible: Python int'L'ulonglongcompatible: C long long'Q'uintplarge enough to fit a pointer'P'uint88 bitsuint1616 bitsuint3232 bitsuint6464 bitsFloating-point numbers 类型 描述 字符代码half'e'singlecompatible: C float'f'doublecompatible: C doublefloat_compatible: Python float'd'longfloatcompatible: C long float'g'float1616 bitsfloat32本文地址:http://www.reviewcode.cn/youxikaifa/203925.html 转载请注明出处!
伍佰目录声明:本站部分文章来源于网络,版权属于原作者所有。如有转载或引用文章/图片涉及版权问题,请联系我们处理.我们将在第一时间删除! 联系邮箱:[email protected]