code: def matrix2map(data_matrix, map_shape):
      r
  
      map_shape = np.array(map_shape)
  
      # Get the shape and layout of the images
      image_shape = np.sqrt(data_matrix.shape[0]).astype(int)
      layout = np.array(map_shape // np.repeat(image_shape, 2), dtype='int')
  
      # Map objects from matrix
      data_map = np.zeros(map_shape)
  
      temp = data_matrix.reshape(image_shape, image_shape, data_matrix.shape[1])
  
      for i in range(data_matrix.shape[1]):
          lower = (image_shape * (i // layout[1]),
                   image_shape * (i % layout[1]))
          upper = (image_shape * (i // layout[1] + 1),
                   image_shape * (i % layout[1] + 1))
          data_map[lower[0]:upper[0], lower[1]:upper[1]] = temp[:, :, i]
  
      return data_map.astype(int)
docs: r"""Matrix to Map
  
      This method transforms a 2D matrix to a 2D map
  
      Parameters
      ----------
      data_matrix : np.ndarray
          Input data matrix, 2D array
      map_shape : tuple
          2D shape of the output map
  
      Returns
      -------
      np.ndarray 2D map
  
      Raises
      ------
      ValueError
          For invalid layout
  
      Examples
      --------
      >>> from modopt.base.transform import matrix2map
      >>> a = np.array([[0, 4, 8, 12], [1, 5, 9, 13], [2, 6, 10, 14],
      [3, 7, 11, 15]])
      >>> matrix2map(a, (2, 2))
      array([[ 0,  1,  4,  5],
             [ 2,  3,  6,  7],
             [ 8,  9, 12, 13],
             [10, 11, 14, 15]])