Skip to content

Instantly share code, notes, and snippets.

@yenchenlin
Created May 19, 2016 01:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yenchenlin/4e61c9e41d0a0f8369801f75442af3e6 to your computer and use it in GitHub Desktop.
Save yenchenlin/4e61c9e41d0a0f8369801f75442af3e6 to your computer and use it in GitHub Desktop.
import numpy as np
from scipy import sparse as sp
from sklearn.datasets.samples_generator import make_blobs
from csr_row_norms import csr_row_norms
import timeit

centers = np.array([
    [0.0, 5.0, 0.0, 0.0, 0.0],
    [1.0, 1.0, 4.0, 0.0, 0.0],
    [1.0, 0.0, 0.0, 5.0, 1.0],
    [0.0, 5.0, 0.0, 0.0, 0.0],
    [1.0, 1.0, 4.0, 0.0, 0.0],
    [1.0, 0.0, 0.0, 5.0, 1.0],
    [0.0, 5.0, 0.0, 0.0, 0.0],
    [1.0, 1.0, 4.0, 0.0, 0.0],
    [1.0, 0.0, 0.0, 5.0, 1.0],
    [0.0, 5.0, 0.0, 0.0, 0.0],
    [1.0, 1.0, 4.0, 0.0, 0.0],
    [1.0, 0.0, 0.0, 5.0, 1.0],
])
n_samples = 10000
n_clusters, n_features = centers.shape
X, true_labels = make_blobs(n_samples=n_samples, centers=centers,
                            cluster_std=1., random_state=42)
X_csr = sp.csr_matrix(X)

def test():
    return csr_row_norms(X_csr)

print timeit.timeit(test, number=10000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment