NumCpp  2.12.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
corrcoef.hpp
Go to the documentation of this file.
1
28#pragma once
29
34#include "NumCpp/NdArray.hpp"
35
36namespace nc
37{
38 //============================================================================
39 // Method Description:
49 template<typename dtype>
51 {
53
54 const auto covariance = cov(x);
55 auto normalizedCovariance = empty_like(covariance);
56 for (decltype(covariance.numRows()) i = 0; i < covariance.numRows(); ++i)
57 {
58 for (decltype(covariance.numCols()) j = 0; j < covariance.numCols(); ++j)
59 {
60 normalizedCovariance(i, j) = covariance(i, j) / sqrt(covariance(i, i) * covariance(j, j));
61 }
62 }
63
64 return normalizedCovariance;
65 }
66} // namespace nc
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition: StaticAsserts.hpp:56
constexpr auto j
Definition: Core/Constants.hpp:42
Definition: Cartesian.hpp:40
NdArray< double > cov(const NdArray< dtype > &x, Bias bias=Bias::NO)
Definition: cov.hpp:53
NdArray< dtype > empty_like(const NdArray< dtype > &inArray)
Definition: empty_like.hpp:44
auto sqrt(dtype inValue) noexcept
Definition: sqrt.hpp:48
NdArray< double > corrcoef(const NdArray< dtype > &x)
Definition: corrcoef.hpp:50