Pra*_*shi 3 python numpy numpy-dtype
我正在尝试使用 numpy,当使用内置方法 dtype.Following 我得到的几个结果时,我遇到了以下数据类型。你能解释一下u11是什么意思吗
a1 = np.array([3,5,'p'])
print(a1.dtype)
Run Code Online (Sandbox Code Playgroud)
o/p = >U11
作为PyArrayObject类型的Numpy 的数组对象具有一个NPY_PRIORITY属性,该属性表示类型的优先级,dtype如果它包含具有异构数据类型的项目,则应将其视为数组的优先级。您可以使用PyArray_GetPriorityAPI访问此优先级 ,__array_priority__如果不存在该名称的属性,则该API 返回obj 或 def的属性(转换为双精度值)。在这种情况下,Unicode 比整数类型具有更高的优先级,这就是为什么a1.dtype返回U11.
现在,关于U11或 一般而言U#,它由两部分组成。在U其中表示的Unicodedtype和#表示它可以容纳元件的数量。不过,这在不同的平台上可能会有所不同。
In [45]: a1.dtype
Out[45]: dtype('<U21') # 64bit Linux
In [46]: a1.dtype.type # The type object used to instantiate a scalar of this data-type.
Out[46]: numpy.str_
In [49]: a1.dtype.itemsize
Out[49]: 84 # 21 * 4
Run Code Online (Sandbox Code Playgroud)
在文档https://docs.scipy.org/doc/numpy-1.14.0/reference/arrays.dtypes.html#data-type-objects-dtype 中阅读有关字符串类型和其他数据类型对象的更多详细信息。
| 归档时间: |
|
| 查看次数: |
5879 次 |
| 最近记录: |