<commit_before>class ArgumentError(ValueError):
    """Invalid argument exception"""
    pass<commit_msg>add function to convert activation to image<commit_after>class ArgumentError(ValueError):
    '''Invalid argument exception'''
    pass

def to_image(array):
    '''Convert a float array to 8bit grayscale

    Parameters
    ----------
    array   :   np.ndarray
                Array of 2/3 dimensions and numeric dtype. In case of 3 dimensions, the image set is
                normalized globally.

    Returns
    -------
    np.ndarray
        Array mapped to [0,255]

    '''
    import numpy as np
    if array.ndim not in {2, 3}:
        raise ArgumentError(f'Array must have 2 or 3 dimensions, has {array.ndim}')

    # normalization (values should be between 0 and 1)
    min_value = array.min()
    max_value = array.max()
    div = max(max_value - min_value, 1)
    return (((array - min_value) / div) * 255).astype(np.uint8)
{'fraction_non_alphanumeric': 0.10828025477707007, 'fraction_numerical': 0.020169851380042462, 'mean_word_length': 2.4925925925925925, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '839218', 'n_tokens_mistral': 288, 'n_tokens_neox': 264, 'n_words': 94}