def coarsen_matrix(Z, xlevel=<NUM_LIT:0>, ylevel=<NUM_LIT:0>, method='<STR_LIT>'):
<EOL>if not ylevel:<EOL><INDENT>Z_coarsened = Z<EOL><DEDENT>else:<EOL><INDENT>temp = []<EOL>for z in Z: temp.append(coarsen_array(z, ylevel, method))<EOL>Z_coarsened = _n.array(temp)<EOL><DEDENT>if xlevel:<EOL><INDENT>Z_coarsened = Z_coarsened.transpose()<EOL>temp = []<EOL>for z in Z_coarsened: temp.append(coarsen_array(z, xlevel, method))<EOL>Z_coarsened = _n.array(temp).transpose()<EOL><DEDENT>return Z_coarsened<EOL>if ylevel:<EOL><INDENT>Z_ycoarsened = []<EOL>for c in Z: Z_ycoarsened.append(coarsen_array(c, ylevel, method))<EOL>Z_ycoarsened = _n.array(Z_ycoarsened)<EOL><DEDENT>if xlevel: return coarsen_array(Z_ycoarsened, xlevel, method)<EOL>else:      return _n.array(Z_ycoarsened)<EOL>
This returns a coarsened numpy matrix.

method can be 'average', 'maximum', or 'minimum'