def center_matrix(M, dim=0):
 M = np.asarray(M, float)
 if dim:
  M = ((M - M.mean(axis=0)) / M.std(axis=0))
 else:
  M = (M - M.mean(axis=1)[:, np.newaxis])
  M = (M / M.std(axis=1)[:, np.newaxis])
 return M

def center_matrix ( M , dim = 0 ) : M = np . asarray ( M , float ) if dim : M = ( ( M - M . mean ( axis = 0 ) ) / M . std ( axis = 0 ) ) else : M = ( M - M . mean ( axis = 1 ) [ : , np . newaxis ] ) M = ( M / M . std ( axis = 1 ) [ : , np . newaxis ] ) return M
return the matrix *m* with each row having zero mean and unit std .