第一个问题的答案:a是一个向量,b是一个矩阵。查看此 stackoverflow 链接了解更多详情:Difference between numpy.array shape (R, 1) and (R,)
第二个问题的答案:
我认为将一种形式转换为另一种形式应该可以正常工作。对于您提供的函数,我猜它需要向量,因此只需使用 b = b.reshape(-1) 重塑 b 即可将其转换为单个维度(向量)。请看以下示例以供参考:
>>> 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