Skip to main content
 首页 » 编程设计

python之属性 numpy.dtype.base 的目的/状态

2024年12月31日8mfryf

我在 numpy.dtype 对象上找到了一个名为 base 的属性。做一些实验:

numpy.dtype('i4').base 
# dtype('int32') 
numpy.dtype('6i4').base 
# dtype('int32') 
numpy.dtype('10f8').base 
# dtype('float64') 
numpy.dtype('3i4, 2f4') 
# dtype([('f0', '<i4', (3,)), ('f1', '<f4', (2,))]) 

所以它似乎包含单个元素的 dtype 用于简单的子数组数据类型,它本身用于结构化数据类型。

不幸的是,这个属性似乎没有在任何地方记录。 有一个page in the documentation ,但它是空的,没有链接到任何地方。奇怪的是,numpy 版本 1.15.0 的文档中也没有具体说明:

我能否在 numpy 的 future 版本中依赖此属性的存在和行为?

请您参考如下方法:

现在记录在案:

https://numpy.org/doc/stable/reference/generated/numpy.dtype.base.html#numpy.dtype.base

定义在https://github.com/numpy/numpy/blob/eeef9d4646103c3b1afd3085f1393f2b3f9575b2/numpy/core/src/multiarray/descriptor.c#L2255-L2300从 git-blame 上次被触及到大约 13 年前,所以可以安全地假设 dtype.base 将存在并继续存在。