No title Revision 663934333737 (Wed Apr 27 2011 at 08:23) - Diff Link to this snippet: https://friendpaste.com/3TwKVt61Eag45X66fpHcpX Embed: manni perldoc borland colorful default murphy trac fruity autumn bw emacs pastie friendly Show line numbers Wrap lines 1234567891011121314151617181920212223242526272829303132333435In [3]: from scikits.learn.preprocessing.sparse import *In [4]: from scikits.learn.utils import inplace_row_normalizeIn [6]: from scipy.sparse import coo_matrixIn [7]: nnz = 10000000In [8]: a = coo_matrix((np.random.normal(size=(nnz,)), np.random.randint(0, 500000, size=(2, nnz)))).tocsr()In [9]: %timeit a.copy()1 loops, best of 3: 253 ms per loopIn [10]: %timeit inplace_row_normalize(a.copy(), norm=1)1 loops, best of 3: 762 ms per loopIn [11]: %timeit normalize_axis1_sparse(a.copy())1 loops, best of 3: 379 ms per loopIn [12]: %timeit inplace_row_normalize(a.copy(), norm=2)1 loops, best of 3: 666 ms per loopIn [13]: %timeit normalize_length_axis1_sparse(a.copy())1 loops, best of 3: 377 ms per loopIn [14]: b = a.copy()In [15]: _ = inplace_row_normalize(b, norm=1)In [16]: c = a.copy()In [17]: _ = normalize_axis1_sparse(c)In [18]: np.abs(b.data - c.data).max()Out[18]: 1.1102230246251565e-16