# About the correlation coefficient of numpy

Asked 3 months ago, Updated 3 months ago, 8 views

Hello, I have a question about python's numpy.
When calculating the correlation coefficient, you can calculate it using `numpy.corrcoef`, but to verify the formula, `cov/(numpy.std(X)*numpy.cov(X)*numpy.numpy.numpy.numpy.numpy.numpy).I would appreciate it if someone could tell me the cause of this`

```The values for each are as follows: · numpy.corrcoef (two-dimensional array of X and Y):```

``````array([1., -0.55847735],
[-0.55847735,  1.        ]])
``````

`·numpy.cov (two-dimensional array of X and Y):`

```:array([7.01969195e-01, -2.42092650e+01], [-2.42092650e+01, 2.67691160e+03]) ·numpy.std(X):0.8375159287888337 ·numpy.std(Y):51.719112506809196 ·numpy.cov(two-dimensional array of X and Y)/(numpy.std(X)*numpy.std(Y)):array([1.61935480e-02, -5.58477348e-01], [- 5.58477348e-01, 6.17529897e+01]]) Thank you for your cooperation. python3 numpy 2022-09-30 14:21 ```
``` ```
``` 1 Answers np.cov() defaults to dof=1, while np.std() defaults to dof=0. Therefore, specifying dof=1 for np.std() yields the same results as np.corrcoef().In:import numpy as np In: np.random.seed(0) ...: X,Y = np.random.rand(21000) In: np.corrcoef(X,Y) Out : array([1., 0.00601658], [0.00601658, 1. ]]) # NG In: np.cov(X,Y)/(np.std(X)*np.std(Y)) Out : array([0.97301135, 0.0060226], [0.0060226 , 1.0297958 ]]) # OK. In: np.cov(X,Y)/(np.std(X,dof=1)*np.std(Y,dof=1)) Out : array([0.97203834, 0.00601658], [0.00601658, 1.028766 ]]) Just to be sure, the upper left and lower right are not 1. because they divide X and X covariance (dispersion of X) and Y and Y covariance (dispersion of Y) by X and Y covariance of Y. 2022-09-30 14:21 If you have any answers or tips ```
``` Popular Tags python x 4566 android x 1593 java x 1484 javascript x 1415 c x 916 c++ x 866 ruby-on-rails x 694 php x 688 python3 x 675 html x 650 Popular Questions 355 I want to get the number of elements in the array of non-static members of the class as a constant expression 352 rails db:create error: Could not find mysql2-0.5.4 in any of the sources 354 JSON.parse fails even though there is no problem with the format. 356 I want to change the format (date and time display) of the legend in chronological order. 354 Understanding How to Configure Google API Key ```
``` window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-109404861-1'); //아이콘 설정 feather.replace({color: '#ffc107', width: 12, height: 12}); //oembed document.querySelectorAll('oembed[url]').forEach(element => { const anchor = document.createElement('a'); anchor.setAttribute('href', element.getAttribute('url')); anchor.className = 'embedly-card'; element.appendChild(anchor); }); \$(document).ready(function () { // 스크랩 \$('#q_scrap').click(function () { \$.post("/scrap", {'qid': "11126"}, function (data) { }); \$('#q_scrap').popover('show'); setTimeout(function () { \$('#q_scrap').popover('hide'); }, 1000); }); //질문 추천 \$('#q_score').click(function () { if (\$(this).attr("data-on") == "off") { \$.post("/score_q", {'qid': "11126"}, function (data) { if (data == "OK") { var score = parseInt(\$('#q_score_num').text()) + 1; \$('#q_score_num').html(score); \$(this).attr("data-on", "on"); } }); } }); //신고 \$('#q_spam').click(function () { \$.post("/spam", {'qid' : "11126"}, function (data) { }); \$('#q_spam').popover('show'); setTimeout(function () { \$('#q_spam').popover('hide'); }, 1000); }); //수정 \$('#q_edit').click(function () { \$(location).attr('href', "/question/edit/11126"); }); //삭제 \$('#q_del').click(function () { \$(location).attr('href', "/question/delete/11126"); }); // 답글 추가 \$('#a_add').click(function () { \$(location).attr('href', "/answer/add/11126"); }); // 답글 수정 \$('.a_edit').click(function () { var aid = \$(this).attr("data-aid"); \$(location).attr('href', "/answer/edit/" + aid); }); //답글 삭제 \$('.a_del').click(function () { if (!confirm('Do you want to delete this answer?')) { return false; } var aid = \$(this).attr("data-aid"); \$(location).attr('href', "/answer/delete/" + aid); }); //답글 추천 \$('.a_score').click(function () { if (\$(this).attr("data-on") == "off") { \$(this).attr("data-on", "on"); var aid = \$(this).attr('data-aid'); \$.post("/score_a", {'aid': aid}, function (data) { if (data == "OK") { var score = parseInt(\$('#a_score_'+aid).text()) + 1; \$('#a_score_'+aid).html(score); } }); } }); }); © 2023 OneMinuteCode. All rights reserved. ```