def fetch_weights(model_weights, layer_id):
    """
    Get weights of a layer

    Parameters
    ----------
    model_weights : :class:`CASTable`
        CASTable of the model weights.
    layer_id : int
        ID of the layer.

    Returns
    -------
    list
        List of weights of the layer

    """
    layer_weights = model_weights.query('_LayerID_ = {}'.format(layer_id))
    n = layer_weights.numrows()['numrows']
    return layer_weights.fetch(maxRows=n, to=n, sortBy='_WeightID_')['Fetch'][
        '_Weight_'].tolist()
