def PCANode_reduce_output_dim(pca_node, new_output_dim, verbose=False):
    """ This function modifies an already trained PCA node,
    reducing the number of preserved SFA features to new_output_dim features.
    The modification is done in place. Also the explained variance field is
    updated.
    """
    if verbose:
        print('Updating the output dimensionality of PCA node')
    if new_output_dim > pca_node.output_dim:
        er = 'Cannot increase the output dimensionality of the PCA node'
        raise ValueError(er)
    original_total_variance = pca_node.d.sum()
    original_explained_variance = pca_node.explained_variance
    pca_node.d = pca_node.d[0:new_output_dim]
    pca_node.v = pca_node.v[:, 0:new_output_dim]
    pca_node._output_dim = new_output_dim
    pca_node.explained_variance = original_explained_variance * pca_node.d.sum(
        ) / original_total_variance
