<p><strong>第一个问题的答案:<code>a</code>是一个向量,<code>b</code>是一个矩阵。有关更多详细信息,请查看此stackoverflow链接:<a href="https://stackoverflow.com/questions/22053050/difference-between-numpy-array-shape-r-1-and-r">Difference between numpy.array shape (R, 1) and (R,)</a></p>
<p><strong>第二个问题的答案</strong>:</p>
<p>我认为把一种形式转换成另一种形式应该很好。对于您提供的函数,我想它需要向量,因此只需使用<code>b = b.reshape(-1)</code>重塑b,它将其转换为单个维度(向量)。请参考以下示例:</p>
<pre class="lang-py prettyprint-override"><code>>>> import numpy as np
>>> from scipy.stats import pearsonr
>>> a = np.random.random((100,))
>>> b = np.random.random((100,1))
>>> print(a.shape, b.shape)
(100,) (100, 1)
>>> p, r= pearsonr(a, b)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\xyz\Appdata\Local\Continuum\Anaconda3\lib\site-packages\scipy\stats\stats.py", line 3042, in pearsonr
r = max(min(r, 1.0), -1.0)
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
>>> b = b.reshape(-1)
>>> p, r= pearsonr(a, b)
>>> print(p, r)
0.10899671932026986 0.280372238354364
</code></pre>