search
Search
Unlock 100+ guides
search toc
close
Cancel
Post
account_circle
Profile
exit_to_app
Sign out
What does this mean?
Why is this true?
Give me some examples!
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

# NumPy | corrcoef method

schedule Aug 12, 2023
Last updated
local_offer
PythonNumPy
Tags
expand_more
mode_heat
Master the mathematics behind data science with 100+ top-tier guides
Start your free 7-days trial now!

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. ]]) 
Edited by 0 others
thumb_up
thumb_down
Comment
Citation
Ask a question or leave a feedback...
thumb_up
4
thumb_down
2
chat_bubble_outline
0
settings
Enjoy our search
Hit / to insta-search docs and recipes!