#NEWLINE# def _transform_selected( X , transform , selected = 'all' , copy = True ) : #NEWLINE# #INDENT# 'Apply a transform function to portion of selected features\n\n    Parameters\n    ----------\n    X : {array-like, sparse matrix}, shape [n_samples, n_features]\n        Dense array or sparse matrix.\n\n    transform : callable\n        A callable transform(X) -> X_transformed\n\n    copy : boolean, optional\n        Copy X even if it could be avoided.\n\n    selected: "all" or array of indices or mask\n        Specify which features to apply the transform to.\n\n    Returns\n    -------\n    X : array or sparse matrix, shape=(n_samples, n_features_new)\n    ' #NEWLINE# if ( isinstance ( selected , six . string_types ) and ( selected == 'all' ) ) : #NEWLINE# #INDENT# return transform ( X ) #NEWLINE# #UNINDENT# X = check_array ( X , accept_sparse = 'csc' , copy = copy , dtype = FLOAT_DTYPES ) #NEWLINE# if ( len ( selected ) == 0 ) : #NEWLINE# #INDENT# return X #NEWLINE# #UNINDENT# n_features = X . shape [ 1 ] #NEWLINE# ind = np . arange ( n_features ) #NEWLINE# sel = np . zeros ( n_features , dtype = bool ) #NEWLINE# sel [ np . asarray ( selected ) ] = True #NEWLINE# not_sel = np . logical_not ( sel ) #NEWLINE# n_selected = np . sum ( sel ) #NEWLINE# if ( n_selected == 0 ) : #NEWLINE# #INDENT# return X #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( n_selected == n_features ) : #NEWLINE# #INDENT# return transform ( X ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# X_sel = transform ( X [ : , ind [ sel ] ] ) #NEWLINE# X_not_sel = X [ : , ind [ not_sel ] ] #NEWLINE# if ( sparse . issparse ( X_sel ) or sparse . issparse ( X_not_sel ) ) : #NEWLINE# #INDENT# return sparse . hstack ( ( X_sel , X_not_sel ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return np . hstack ( ( X_sel , X_not_sel ) )