<p><a href="https://github.com/numpy/numpy/blob/4ed1587a7de85b4fa01dff8ef6e0e901a25f149c/numpy/core/numeric.py#L1655-L1660" rel="nofollow">Here</a>是在<code>numeric.py</code>内构造<code>_typelessdata</code>的行:</p>
<pre><code>_typelessdata = [int_, float_, complex_]
if issubclass(intc, int):
_typelessdata.append(intc)
if issubclass(longlong, int):
_typelessdata.append(longlong)
</code></pre>
<p><code>intc</code>是一个与C兼容的(32位)有符号整数,<code>int</code>是本机Python
整数,可能是32位或64位,具体取决于平台。在</p>
<ul>
<li><p>位{32位Python也是本机类型
<code>issubclass(intc, int)</code>返回<code>True</code>,而<code>intc</code>被附加到<code>_typelessdata</code>,
结果是这样的:</p>
^{pr2}$
<p>注意<code>_typelessdata[-1] is numpy.intc</code>,而不是{<cd11>}。</p></li>
<li><p>在64位系统中,<code>int</code>是64位,因此<code>issubclass(longlong, int)</code>返回{<cd7>},并且<code>longlong</code>被附加到<code>_typelessdata</code>,结果是:</p>
<pre><code>[numpy.int64, numpy.float64, numpy.complex128, numpy.int64]
</code></pre>
<p>在这种情况下,正如Joe所指出的,<code>(_typelessdata[-1] is numpy.longlong) == True</code>。</p></li>
</ul>
<hr/>
<p>更大的问题是<em>为什么<code>_typelessdata</code>的内容是这样设置的。
我在numpy源代码中唯一能找到<code>_typelessdata</code>的地方
实际使用的是<a href="https://github.com/numpy/numpy/blob/4ed1587a7de85b4fa01dff8ef6e0e901a25f149c/numpy/core/numeric.py#L1715" rel="nofollow">this line</a>在<a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.array_repr.html" rel="nofollow">^{<cd20>}</a>的定义内
在同一个文件中:</p>
<pre><code>skipdtype = (arr.dtype.type in _typelessdata) and arr.size > 0
</code></pre>
<p><code>_typelessdata</code>的目的是确保<code>np.array_repr</code>正确地打印<code>dtype</code>恰好与(依赖于平台的)本机Python整数类型相同的数组的字符串表示。在</p>
<p>例如,在32位系统中,<code>int</code>是32位:</p>
<pre><code>In [1]: np.array_repr(np.intc([1]))
Out[1]: 'array([1])'
In [2]: np.array_repr(np.longlong([1]))
Out[2]: 'array([1], dtype=int64)'
</code></pre>
<p>而在64位系统中,<code>int</code>是64位:</p>
<pre><code>In [1]: np.array_repr(np.intc([1]))
Out[1]: 'array([1], dtype=int32)'
In [2]: np.array_repr(np.longlong([1]))
Out[2]: 'array([1])'
</code></pre>
<p>上面一行中的<code>arr.dtype.type in _typelessdata</code>检查可确保为适当的依赖于平台的本机整数<code>dtypes</code>跳过打印{<cd23>}。在</p>