<s> import random <EOL> import numpy as np <EOL> from scipy . sparse import coo_matrix <EOL> from sklearn . utils . testing import assert_array_equal <EOL> def get_random_coo_matrix ( rows = <NUM_LIT:3> , cols = <NUM_LIT:10> , nnz = <NUM_LIT:20> ) : <EOL> row_col = random . sample ( xrange ( rows * cols ) , nnz ) <EOL> row = [ i // cols for i in row_col ] <EOL> col = [ i % cols for i in row_col ] <EOL> data = np . random . randint ( <NUM_LIT:0> , nnz * <NUM_LIT:5> , nnz ) <EOL> return coo_matrix ( ( data , ( row , col ) ) , shape = ( rows , cols ) ) <EOL> def assert_sparse_matrix_equal ( X , Y ) : <EOL> expected = X . toarray ( ) <EOL> actual = Y . toarray ( ) <EOL> expected = expected [ : actual . shape [ <NUM_LIT:0> ] , : actual . shape [ <NUM_LIT:1> ] ] <EOL> assert_array_equal ( expected , actual ) </s>
