def rotate_and_truncate(operator, transformation_matrix):
    """
    Transforms the operator to the new (possibly truncated) basis given by transformation matrix.
    :param operator: operator to transform (np.array).
    :param transformation_matrix:   transformation matrix (np.array).
    :return: transformed matrix.
    """
    return transformation_matrix.conjugate().transpose().dot(operator.dot(transformation_matrix))