Skip to content

Instantly share code, notes, and snippets.

@wiso
Created March 20, 2018 08:33
Show Gist options
  • Select an option

  • Save wiso/ce2a9919ded228838703c1c7c7dad13b to your computer and use it in GitHub Desktop.

Select an option

Save wiso/ce2a9919ded228838703c1c7c7dad13b to your computer and use it in GitHub Desktop.

Revisions

  1. wiso revised this gist Mar 20, 2018. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions covariance_to_correlation.py
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    import numpy as np

    def correlation_from_covariance(covariance):
    v = np.sqrt(np.diag(covariance))
    outer_v = np.outer(v, v)
  2. wiso created this gist Mar 20, 2018.
    6 changes: 6 additions & 0 deletions covariance_to_correlation.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    def correlation_from_covariance(covariance):
    v = np.sqrt(np.diag(covariance))
    outer_v = np.outer(v, v)
    correlation = covariance / outer_v
    correlation[covariance == 0] = 0
    return correlation