parameters: (X, norm='l2', axis=1, copy=True, return_norm=False)
docstring: Scale input vectors individually to unit norm (vector length).
  
      Read more in the :ref:`User Guide <preprocessing_normalization>`.
  
      Parameters
      ----------
      X : {array-like, sparse matrix}, shape [n_samples, n_features]
          The data to normalize, element by element.
          scipy.sparse matrices should be in CSR format to avoid an
          un-necessary copy.
  
      norm : 'l1', 'l2', or 'max', optional ('l2' by default)
          The norm to use to normalize each non zero sample (or each non-zero
          feature if axis is 0).
  
      axis : 0 or 1, optional (1 by default)
          axis used to normalize the data along. If 1, independently normalize
          each sample, otherwise (if 0) normalize each feature.
  
      copy : boolean, optional, default True
          set to False to perform inplace row normalization and avoid a
          copy (if the input is already a numpy array or a scipy.sparse
          CSR matrix and if axis is 1).
  
      return_norm : boolean, default False
          whether to return the computed norms
  
      Returns
      -------
      X : {array-like, sparse matrix}, shape [n_samples, n_features]
          Normalized input X.
  
      norms : array, shape [n_samples] if axis=1 else [n_features]
          An array of norms along given axis for X.
          When X is sparse, a NotImplementedError will be raised
          for norm 'l1' or 'l2'.
  
      See also
      --------
      Normalizer: Performs normalization using the ``Transformer`` API
          (e.g. as part of a preprocessing :class:`sklearn.pipeline.Pipeline`).
  
      Notes
      -----
      For a comparison of the different scalers, transformers, and normalizers,
      see :ref:`examples/preprocessing/plot_all_scaling.py
      <sphx_glr_auto_examples_preprocessing_plot_all_scaling.py>`.
docstring_summary: Scale input vectors individually to unit norm (vector length).
docstring_tokens: Scale input vectors individually to unit norm ( vector length ) .
function: def normalize(X, norm='l2', axis=1, copy=True, return_norm=False):
      """Scale input vectors individually to unit norm (vector length).
  
      Read more in the :ref:`User Guide <preprocessing_normalization>`.
  
      Parameters
      ----------
      X : {array-like, sparse matrix}, shape [n_samples, n_features]
          The data to normalize, element by element.
          scipy.sparse matrices should be in CSR format to avoid an
          un-necessary copy.
  
      norm : 'l1', 'l2', or 'max', optional ('l2' by default)
          The norm to use to normalize each non zero sample (or each non-zero
          feature if axis is 0).
  
      axis : 0 or 1, optional (1 by default)
          axis used to normalize the data along. If 1, independently normalize
          each sample, otherwise (if 0) normalize each feature.
  
      copy : boolean, optional, default True
          set to False to perform inplace row normalization and avoid a
          copy (if the input is already a numpy array or a scipy.sparse
          CSR matrix and if axis is 1).
  
      return_norm : boolean, default False
          whether to return the computed norms
  
      Returns
      -------
      X : {array-like, sparse matrix}, shape [n_samples, n_features]
          Normalized input X.
  
      norms : array, shape [n_samples] if axis=1 else [n_features]
          An array of norms along given axis for X.
          When X is sparse, a NotImplementedError will be raised
          for norm 'l1' or 'l2'.
  
      See also
      --------
      Normalizer: Performs normalization using the ``Transformer`` API
          (e.g. as part of a preprocessing :class:`sklearn.pipeline.Pipeline`).
  
      Notes
      -----
      For a comparison of the different scalers, transformers, and normalizers,
      see :ref:`examples/preprocessing/plot_all_scaling.py
      <sphx_glr_auto_examples_preprocessing_plot_all_scaling.py>`.
  
      """
      if norm not in ('l1', 'l2', 'max'):
          raise ValueError("'%s' is not a supported norm" % norm)
  
      if axis == 0:
          sparse_format = 'csc'
      elif axis == 1:
          sparse_format = 'csr'
      else:
          raise ValueError("'%d' is not a supported axis" % axis)
  
      X = check_array(X, sparse_format, copy=copy,
                      estimator='the normalize function', dtype=FLOAT_DTYPES)
      if axis == 0:
          X = X.T
  
      if sparse.issparse(X):
          if return_norm and norm in ('l1', 'l2'):
              raise NotImplementedError("return_norm=True is not implemented "
                                        "for sparse matrices with norm 'l1' "
                                        "or norm 'l2'")
          if norm == 'l1':
              inplace_csr_row_normalize_l1(X)
          elif norm == 'l2':
              inplace_csr_row_normalize_l2(X)
          elif norm == 'max':
              _, norms = min_max_axis(X, 1)
              norms_elementwise = norms.repeat(np.diff(X.indptr))
              mask = norms_elementwise != 0
              X.data[mask] /= norms_elementwise[mask]
      else:
          if norm == 'l1':
              norms = np.abs(X).sum(axis=1)
          elif norm == 'l2':
              norms = row_norms(X)
          elif norm == 'max':
              norms = np.max(X, axis=1)
          norms = _handle_zeros_in_scale(norms, copy=False)
          X /= norms[:, np.newaxis]
  
      if axis == 0:
          X = X.T
  
      if return_norm:
          return X, norms
      else:
          return X
function_tokens: def normalize ( X , norm = 'l2' , axis = 1 , copy = True , return_norm = False ) : if norm not in ( 'l1' , 'l2' , 'max' ) : raise ValueError ( "'%s' is not a supported norm" % norm ) if axis == 0 : sparse_format = 'csc' elif axis == 1 : sparse_format = 'csr' else : raise ValueError ( "'%d' is not a supported axis" % axis ) X = check_array ( X , sparse_format , copy = copy , estimator = 'the normalize function' , dtype = FLOAT_DTYPES ) if axis == 0 : X = X . T if sparse . issparse ( X ) : if return_norm and norm in ( 'l1' , 'l2' ) : raise NotImplementedError ( "return_norm=True is not implemented " "for sparse matrices with norm 'l1' " "or norm 'l2'" ) if norm == 'l1' : inplace_csr_row_normalize_l1 ( X ) elif norm == 'l2' : inplace_csr_row_normalize_l2 ( X ) elif norm == 'max' : _ , norms = min_max_axis ( X , 1 ) norms_elementwise = norms . repeat ( np . diff ( X . indptr ) ) mask = norms_elementwise != 0 X . data [ mask ] /= norms_elementwise [ mask ] else : if norm == 'l1' : norms = np . abs ( X ) . sum ( axis = 1 ) elif norm == 'l2' : norms = row_norms ( X ) elif norm == 'max' : norms = np . max ( X , axis = 1 ) norms = _handle_zeros_in_scale ( norms , copy = False ) X /= norms [ : , np . newaxis ] if axis == 0 : X = X . T if return_norm : return X , norms else : return X