def center_matrix(M, dim=<NUM_LIT:0>):
M = np.asarray(M, np.float_)<EOL>if dim:<EOL><INDENT>M = (M - M.mean(axis=<NUM_LIT:0>)) / M.std(axis=<NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>M = (M - M.mean(axis=<NUM_LIT:1>)[:,np.newaxis])<EOL>M = M / M.std(axis=<NUM_LIT:1>)[:,np.newaxis]<EOL><DEDENT>return M<EOL>
Return the matrix *M* with each row having zero mean and unit std.

If *dim* = 1 operate on columns instead of rows.  (*dim* is
opposite to the numpy axis kwarg.)