test_csc.py 859 B

123456789101112131415161718192021222324252627282930313233343536
  1. from __future__ import division, print_function, absolute_import
  2. import numpy as np
  3. from numpy.testing import assert_array_almost_equal, assert_
  4. from scipy.sparse import csr_matrix, csc_matrix
  5. def test_csc_getrow():
  6. N = 10
  7. np.random.seed(0)
  8. X = np.random.random((N, N))
  9. X[X > 0.7] = 0
  10. Xcsc = csc_matrix(X)
  11. for i in range(N):
  12. arr_row = X[i:i + 1, :]
  13. csc_row = Xcsc.getrow(i)
  14. assert_array_almost_equal(arr_row, csc_row.toarray())
  15. assert_(type(csc_row) is csr_matrix)
  16. def test_csc_getcol():
  17. N = 10
  18. np.random.seed(0)
  19. X = np.random.random((N, N))
  20. X[X > 0.7] = 0
  21. Xcsc = csc_matrix(X)
  22. for i in range(N):
  23. arr_col = X[:, i:i + 1]
  24. csc_col = Xcsc.getcol(i)
  25. assert_array_almost_equal(arr_col, csc_col.toarray())
  26. assert_(type(csc_col) is csc_matrix)