docstr: X = array([[1., 0., 2.],
             [0., 0., 3.],
             [4., 5., 6.]])
docstr_tok: ["X","=","array","(","[","[","1.",",","0.",",","2",".","]",",","[","0.",",","0.",",","3",".","]",",","[","4.",",","5.",",","6",".","]","]",")"]
code: def test_normalize(self):
      """
      X = array([[1., 0., 2.],
                 [0., 0., 3.],
                 [4., 5., 6.]])
      """
      indptr = np.array([0, 2, 3, 6])
      indices = np.array([0, 2, 2, 0, 1, 2])
      data = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype=np.float64)
      X = sp.csr_matrix((data, indices, indptr), shape=(3, 3))
      XA = X.A
  
      # normalizing rows (axis=1)
      X_l1 = XA / (np.abs(XA).sum(1).reshape(-1, 1))
      X_l2 = XA / (np.sqrt((XA**2).sum(1)).reshape(-1, 1))
      X_max = XA / (np.max(XA, axis=1).reshape(-1, 1))
      # sparse input
      npt.assert_array_equal(
          X_l1, normalize(X, "l1", axis=1, copy=True).A
      )
      npt.assert_array_equal(
          X_l2, normalize(X, "l2", axis=1, copy=True).A
      )
      npt.assert_array_equal(
          X_max, normalize(X, "max", axis=1, copy=True).A
      )
      # dense input
      npt.assert_array_equal(
          X_l1, normalize(XA, "l1", axis=1, copy=True)
      )
      npt.assert_array_equal(
          X_l2, normalize(XA, "l2", axis=1, copy=True)
      )
      npt.assert_array_equal(
          X_max, normalize(XA, "max", axis=1, copy=True)
      )
  
      # normalizing columns (axis=0)
      X_l1 = XA / (np.abs(XA).sum(0).reshape(1, -1))
      X_l2 = XA / (np.sqrt((XA**2).sum(0)).reshape(1, -1))
      X_max = XA / (np.max(XA, axis=0).reshape(1, -1))
      # sparse input
      npt.assert_array_equal(
          X_l1, normalize(X, "l1", axis=0, copy=True).A
      )
      npt.assert_array_equal(
          X_l2, normalize(X, "l2", axis=0, copy=True).A
      )
      npt.assert_array_equal(
          X_max, normalize(X, "max", axis=0, copy=True).A
      )
      # dense input
      npt.assert_array_equal(
          X_l1, normalize(XA, "l1", axis=0, copy=True)
      )
      npt.assert_array_equal(
          X_l2, normalize(XA, "l2", axis=0, copy=True)
      )
      npt.assert_array_equal(
          X_max, normalize(XA, "max", axis=0, copy=True)
      )
  
      # check valid norm type
      try:
          normalize(X, norm="bla bla")
      except ValueError:
          assert True
  
      # check valid input shape
      try:
          normalize(XA[:, np.newaxis])
      except ValueError:
          assert True
  
      # copy=True, sparse
      normalized_X = normalize(X, copy=True)
      self.assertFalse(np.allclose(X.data, normalized_X.data))
  
      # copy=True, dense
      normalized_XA = normalize(XA, copy=True)
      self.assertFalse(np.allclose(XA, normalized_XA))
  
      # copy=False, sparse
      original = X.data.copy()
      normalized_X = normalize(X, copy=False)
      self.assertFalse(np.allclose(original, X.data))
      npt.assert_array_equal(normalized_X.data, X.data)
  
      # copy=False, dense
      original = XA.copy()
      normalized_XA = normalize(XA, copy=False)
      self.assertFalse(np.allclose(original, XA))
      npt.assert_array_equal(normalized_XA, XA)
  
imports: import unittest
  import numpy
  import numpy.testing
  import scipy.sparse
  from cornac.utils.common import sigmoid
  from cornac.utils.common import safe_indexing
  from cornac.utils.common import validate_format
  from cornac.utils.common import scale
  from cornac.utils.common import clip
  from cornac.utils.common import excepts
  from cornac.utils.common import intersects
  from cornac.utils.common import estimate_batches
  from cornac.utils.common import get_rng
  from cornac.utils.common import normalize
label_desc: Use image node_id 10 for calling the TestCommon obj's underlying member method code with example usage: obj.test_normalize() without return types