Skip to content

Instantly share code, notes, and snippets.

@gvyshnya
Created December 17, 2017 09:28
Show Gist options
  • Save gvyshnya/16911ce1411f375524c69f95f7af59b7 to your computer and use it in GitHub Desktop.
Save gvyshnya/16911ce1411f375524c69f95f7af59b7 to your computer and use it in GitHub Desktop.
The code to test the sparsity of your data input
def sparsity_ratio(X):
return 1.0 - np.count_nonzero(X) / float(X.shape[0] * X.shape[1])
print("input sparsity ratio:", sparsity_ratio(X))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment