Numpy 的 corrcoef(~)
方法計算給定兩個數組的 Pearson 相關係數:
參數
1. x
| array-like
每行代表一個單獨的列數據(即變量)。請參閱下麵的示例以進行說明。
2. y
| array-like
| optional
您無需將數據集指定為 x 中的新行,隻需將其指定為 y
即可。
3. rowvar
| boolean
| optional
如果為 True,則 x 中的每一行代表一個變量。如果為 False,則 x 中的每一列代表一個變量。默認情況下,rowvar=True
。
返回值
包含給定數據集的相關係數的 Numpy 數組。
例子
基本用法
np.corrcoef([2,3,5,6],[3,5,8,12])
array([[1. , 0.97913005],
[0.97913005, 1. ]])
這與指定二維數組完全相同:
np.corrcoef([[2,3,5,6],[3,5,8,12]])
array([[1. , 0.97913005],
[0.97913005, 1. ]])
相關用法
- Python codecs.decode()用法及代碼示例
- Python collections.somenamedtuple._replace用法及代碼示例
- Python collections.somenamedtuple._asdict用法及代碼示例
- Python compile()用法及代碼示例
- Python NumPy compress方法用法及代碼示例
- Python collections.somenamedtuple._field_defaults用法及代碼示例
- Python NumPy cov方法用法及代碼示例
- Python codecs.encode()用法及代碼示例
- Python contextlib.AsyncContextDecorator用法及代碼示例
- Python collections.ChainMap用法及代碼示例
- Python contextlib.AsyncExitStack用法及代碼示例
- Python string count()用法及代碼示例
- Python collections.somenamedtuple._make用法及代碼示例
- Python NumPy count_nonzero方法用法及代碼示例
- Python configparser.ConfigParser.readfp用法及代碼示例
- Python code.compile_command()用法及代碼示例
- Python Wand color_matrix()用法及代碼示例
- Python configparser.ConfigParser.BOOLEAN_STATES用法及代碼示例
- Python math copysign()用法及代碼示例
- Python PIL composite()用法及代碼示例
- Python codeop.compile_command用法及代碼示例
- Python contextlib.ExitStack.pop_all用法及代碼示例
- Python contextlib.redirect_stdout用法及代碼示例
- Python collections.Counter用法及代碼示例
- Python configparser.BasicInterpolation用法及代碼示例
注:本文由純淨天空篩選整理自Isshin Inada大神的英文原創作品 NumPy | corrcoef method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。