def binarize(X, threshold=0.0, copy=True):
 X = check_array(X, accept_sparse=['csr', 'csc'], copy=copy)
 if sparse.issparse(X):
  if (threshold < 0):
   raise ValueError('Cannot binarize a sparse matrix with threshold < 0')
  cond = (X.data > threshold)
  not_cond = np.logical_not(cond)
  X.data[cond] = 1
  X.data[not_cond] = 0
  X.eliminate_zeros()
 else:
  cond = (X > threshold)
  not_cond = np.logical_not(cond)
  X[cond] = 1
  X[not_cond] = 0
 return X

def binarize ( X , threshold = 0.0 , copy = True ) : X = check_array ( X , accept_sparse = [ 'csr' , 'csc' ] , copy = copy ) if sparse . issparse ( X ) : if ( threshold < 0 ) : raise ValueError ( 'Cannot binarize a sparse matrix with threshold < 0' ) cond = ( X . data > threshold ) not_cond = np . logical_not ( cond ) X . data [ cond ] = 1 X . data [ not_cond ] = 0 X . eliminate_zeros ( ) else : cond = ( X > threshold ) not_cond = np . logical_not ( cond ) X [ cond ] = 1 X [ not_cond ] = 0 return X
boolean thresholding of array-like or scipy .