search
Search
Guest 0reps
Thanks for the thanks!
close
account_circle
Profile
exit_to_app
Sign out
search
keyboard_voice
close
Searching Tips
Search for a recipe:
"Creating a table in MySQL"
Search for an API documentation: "@append"
Search for code: "!dataframe"
Apply a tag filter: "#python"
Useful Shortcuts
/ to open search panel
Esc to close search panel
to navigate between search results
d to clear all current filters
Enter to expand content preview
Doc Search
Code Search Beta
SORRY NOTHING FOUND!
mic
Start speaking...
Voice search is only supported in Safari and Chrome.
Shrink
Navigate to
A
A
brightness_medium
share
arrow_backShare

# NumPy | corrcoef method

NumPy
chevron_right
Documentation
schedule Jul 1, 2022
Last updated
local_offer PythonNumPy
Tags
expand_more

Numpy's corrcoef(~) method computes the Pearson's correlation coefficient given two arrays:

$$r_{xy}=\frac{\sum^n_{i=1}(x_i-\bar{x})(y_i-\bar{y})}{\sqrt{\sum^n_{i=1}(x_i-\bar{x})^2\sum^n_{i=1}(y_i-\bar{y})^2}}=\frac{\mathrm{cov}(x,y)}{\sqrt{\mathrm{var}(x)\cdot\mathrm{var}(y)}}$$

# Parameters

1. x | array-like

Each row represents a separate column data (i.e. a variable). See the example below for clarification.

2. y | array-like | optional

Instead of specifying your dataset as a new row in x, you can just specify it as y.

3. rowvar | boolean | optional

If True, then each row in x represents a variable. If False, then each column in x represents a variable. By default, rowvar=True.

# Return value

A Numpy array that contains the correlation coefficients of the given dataset.

# Examples

## Basic usage

 np.corrcoef([2,3,5,6],[3,5,8,12]) array([[1. , 0.97913005], [0.97913005, 1. ]]) 

This is exactly the same as specifying a 2D array:

 np.corrcoef([[2,3,5,6],[3,5,8,12]]) array([[1. , 0.97913005], [0.97913005, 1. ]]) 
mail
Edited by 0 others