擅长:python、mysql、java
<p>在<a href="https://docs.python.org/3/library/functions.html#map" rel="nofollow noreferrer">Python 3</a>中,<code>map()</code>返回一个iterable,而在<a href="https://docs.python.org/2.7/library/functions.html#map" rel="nofollow noreferrer">Python 2</a>中,它返回一个列表。python iterable上的任何数学操作,如平方(<code>**</code>),都会抛出类似的错误。行:</p>
<pre><code>d2 = d ** 2
</code></pre>
<p>抛出python3中提到的错误,因为<code>d</code>是函数<code>map()</code>返回的iterable。很可能您正在使用python3。所以您需要在任何数学运算之前将<code>d</code>转换成list,比如<code>d = np.array(list(map(mahalanobis, data)))</code>。在</p>