title: Python: Why would numpy.corrcoef() return NaN values?
body: <p>Why would <code>numpy.corrcoef()</code> return <code>NaN</code> values? </p>
  
  <p>I am working with high dimensional data and it is infeasible to go through every datum to test values. </p>
  
  <pre><code># Import
  from sklearn.preprocessing import StandardScaler
  import pandas as pd
  import numpy as np
  
  # Delete all zero columns
  df = df.loc[:, (df != 0).any(axis=0)]
  
  # Delete any NaN columns
  df = df.dropna(axis='columns', how='any', inplace=False)
  
  # Standardise
  X_std = StandardScaler().fit_transform(df.values)
  print(X_std.dtype) # Returns "float64"
  
  # Correlation
  cor_mat1 = np.corrcoef(X_std.T)
  cor_mat1.max() # Returns nan
  </code></pre>
  
  <p>And then 
  <code>cor_mat1.max()</code></p>
  
  <p>Returns </p>
  
  <blockquote>
    <p>nan</p>
  </blockquote>
  
  <p>When computing <code>cor_mat1 = np.corrcoef(X_std.T)</code>  I get this warning:</p>
  
  <blockquote>
    <p>/Users/kimrants/anaconda3/lib/python3.6/site-packages/numpy/lib/function_base.py:3183:
    RuntimeWarning:</p>
    
    <p>invalid value encountered in true_divide</p>
  </blockquote>
  
  <p>This is a snippet of the input dataframe:
  <a href="https://i.stack.imgur.com/4sd0R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4sd0R.png" alt="enter image description here"></a></p>
  
  <p>To try and fix it myself, I started removing all zero-columns and columns that contained <em>any</em> <code>NaN</code> values. I thought this would solve the problem, but it didn't. Am I missing something? I don't see why else it would return <code>NaN</code> values?</p>
  
  <p>My end goal is to compute eigen-values and -vectors.</p>