def prune_layers(net, subsample_indices):
    """
    Remove layers with no maps and their associated connections. It is possible
    for a layers to lose all its maps in prune_maps().

    :param net: a Network
    :return: updated Network with empty layers and associated connections removed
    """
    new_layers = []

    discarded_names = []
    for layer in net.layers:
        if layer.m > 0:
            new_layers.append(layer)
        else:
            discarded_names.append(layer.name)

    new_connections = []
    new_subsample_indices = []
    for i in range(len(net.connections)):
        connection = net.connections[i]
        if connection.pre.name not in discarded_names and connection.post.name not in discarded_names:
            new_connections.append(connection)
            new_subsample_indices.append(subsample_indices[i])

    net.layers = new_layers
    net.connections = new_connections

    return new_subsample_indices