def _extract_submatrices(M, block_indices, block_size, axis):
 assert (block_indices.ndim == 1)
 assert (axis in [0, 1])
 (r, c) = M.shape
 if (axis == 0):
  sh = [block_indices.shape[0], block_size, c]
 elif (axis == 1):
  sh = [block_indices.shape[0], r, block_size]
 dt = M.dtype
 M_res = np.empty(sh, dtype=dt)
 if (axis == 0):
  for ir in range(block_size):
   M_res[:, ir, :] = M[((block_indices * block_size) + ir), :]
 elif (axis == 1):
  for ic in range(block_size):
   M_res[:, :, ic] = M[:, ((block_indices * block_size) + ic)]
 return M_res

def _extract_submatrices ( M , block_indices , block_size , axis ) : assert ( block_indices . ndim == 1 ) assert ( axis in [ 0 , 1 ] ) ( r , c ) = M . shape if ( axis == 0 ) : sh = [ block_indices . shape [ 0 ] , block_size , c ] elif ( axis == 1 ) : sh = [ block_indices . shape [ 0 ] , r , block_size ] dt = M . dtype M_res = np . empty ( sh , dtype = dt ) if ( axis == 0 ) : for ir in range ( block_size ) : M_res [ : , ir , : ] = M [ ( ( block_indices * block_size ) + ir ) , : ] elif ( axis == 1 ) : for ic in range ( block_size ) : M_res [ : , : , ic ] = M [ : , ( ( block_indices * block_size ) + ic ) ] return M_res
extracts selected blocks of a matrices *m* depending on parameters *block_indices* and *block_size* .