def safe_min(X):
 if issparse(X):
  if (len(X.data) == 0):
   return 0
  m = X.data.min()
  return (m if (X.getnnz() == X.size) else min(m, 0))
 else:
  return X.min()

def safe_min ( X ) : if issparse ( X ) : if ( len ( X . data ) == 0 ) : return 0 m = X . data . min ( ) return ( m if ( X . getnnz ( ) == X . size ) else min ( m , 0 ) ) else : return X . min ( )
returns the minimum value of a dense or a csr/csc matrix .