<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def map2matrix(data_map, layout):
 r"""Map to Matrix This method transforms a 2D map to a 2D matrix Parameters data_map : np.ndarray Input data map, 2D array layout : tuple 2D layout of 2D images Returns ------- np.ndarray 2D matrix Raises ------ ValueError For invalid layout Examples -------- [10, 11, 14, 15]]) array([[ 0, 4, 8, 12], [ 1, 5, 9, 13], [ 2, 6, 10, 14], [ 3, 7, 11, 15]]) """


    layout = np.array(layout)

    # Select n objects
    n_obj = np.prod(layout)

    # Get the shape of the images
    image_shape = (np.array(data_map.shape) // layout)[0]

    # Stack objects from map
    data_matrix = []

    for i in range(n_obj):
        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_matrix.append((data_map[lower[0]:upper[0],
                            lower[1]:upper[1]]).reshape(image_shape ** 2))

    return np.array(data_matrix).T