NumCpp  2.11.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
corrcoef.hpp
Go to the documentation of this file.
1 #pragma once
29 
31 #include "NumCpp/Functions/cov.hpp"
34 #include "NumCpp/NdArray.hpp"
35 
36 namespace 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 > corrcoef(const NdArray< dtype > &x)
Definition: corrcoef.hpp:50
NdArray< double > cov(const NdArray< dtype > &x, bool bias=false)
Definition: cov.hpp:52
auto sqrt(dtype inValue) noexcept
Definition: sqrt.hpp:48
NdArray< dtype > empty_like(const NdArray< dtype > &inArray)
Definition: empty_like.hpp:44