Skip to content
Snippets Groups Projects
Commit bca818f1 authored by s183917's avatar s183917 :speech_balloon:
Browse files

binarize

parent 84b7875d
No related branches found
No related tags found
No related merge requests found
def binarize(X,Y=None):
''' Force binary representation of the matrix, according to X>median(X) '''
x_was_transposed = False
if Y is None:
if X.shape[0] == 1:
x_was_transposed = True
X = X.T;
Xmedians = np.ones((np.shape(X)[0],1)) * np.median(X,0)
Xflags = X>Xmedians
X[Xflags] = 1; X[~Xflags] = 0
if x_was_transposed:
return X.T
return X
else:
#X = np.matrix(X); Y = np.matrix(Y);
#XYmedian= np.median(np.bmat('X; Y'),0)
#Xmedians = np.ones((np.shape(X)[0],1)) * XYmedian
#Xflags = X>Xmedians
#X[Xflags] = 1; X[~Xflags] = 0
#Ymedians = np.ones((np.shape(Y)[0],1)) * XYmedian
#Yflags = Y>Ymedians
#Y[Yflags] = 1; Y[~Yflags] = 0
return [binarize(X,None),binarize(Y,None)]
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment