<commit_before>
import amitgroup as ag
import amitgroup.io
import numpy as np
import os

def datapath(name): 
    return os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', 'data', name) 

def load_example(name):
    """
    Loads example data.

    The `amitgroup` package comes with some subsets of data sets, to use in examples and for quick testing.
    
    Parameters
    ----------
    name : str
        * `"faces"`: loads ``N`` faces into an array of shape ``(N, rows, cols)``.
        * `"two-faces"`: loads 2 faces into an array of shape ``(2, rows, cols)``.
        * `"oldfaithful"`: loads the classic Old Faithful eruption data as an array of shape ``(N, 2)``.
        * `"mnist"`: loads 10 MNIST nines into an array of shape ``(10, rows, cols)``.

    Examples
    --------
    >>> import amitgroup as ag
    >>> import matplotlib.pylab as plt

    Load faces:

    >>> faces = ag.io.load_example("faces")
    >>> ag.plot.images(faces[:4])
    >>> plt.show()

    Load MNIST:

    >>> digits = ag.io.load_example("mnist")
    >>> ag.plot.images(digits[:4])
    >>> plt.show()

    """
    if name == 'faces':
        return ag.io.load_all_images(datapath('Images_0'))
    if name == 'two-faces':
        data = np.load(datapath('twoface.npz'))
        return np.array([data['im1'], data['im2']])
    if name == 'oldfaithful':
        return np.genfromtxt(datapath('oldfaithful'))
    if name == 'mnist':
        return np.load(datapath('nines.npz'))['images']
    else:
        raise ValueError("Example data does not exist")
<commit_msg>load_example('faces') returns a numpy array again.<commit_after>
import amitgroup as ag
import amitgroup.io
import numpy as np
import os

def datapath(name): 
    return os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', 'data', name) 

def load_example(name):
    """
    Loads example data.

    The `amitgroup` package comes with some subsets of data sets, to use in examples and for quick testing.
    
    Parameters
    ----------
    name : str
        * `"faces"`: loads ``N`` faces into an array of shape ``(N, rows, cols)``.
        * `"two-faces"`: loads 2 faces into an array of shape ``(2, rows, cols)``.
        * `"oldfaithful"`: loads the classic Old Faithful eruption data as an array of shape ``(N, 2)``.
        * `"mnist"`: loads 10 MNIST nines into an array of shape ``(10, rows, cols)``.

    Examples
    --------
    >>> import amitgroup as ag
    >>> import matplotlib.pylab as plt

    Load faces:

    >>> faces = ag.io.load_example("faces")
    >>> ag.plot.images(faces[:4])
    >>> plt.show()

    Load MNIST:

    >>> digits = ag.io.load_example("mnist")
    >>> ag.plot.images(digits[:4])
    >>> plt.show()

    """
    if name == 'faces':
        return map(lambda x: x.img, ag.io.load_all_images(datapath('Images_0')))
    if name == 'two-faces':
        data = np.load(datapath('twoface.npz'))
        return np.array([data['im1'], data['im2']])
    if name == 'oldfaithful':
        return np.genfromtxt(datapath('oldfaithful'))
    if name == 'mnist':
        return np.load(datapath('nines.npz'))['images']
    else:
        raise ValueError("Example data does not exist")

{'fraction_non_alphanumeric': 0.1675556950109821, 'fraction_numerical': 0.007530593034201443, 'mean_word_length': 2.719953325554259, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 51, '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': '627621', 'n_tokens_mistral': 1089, 'n_tokens_neox': 1052, 'n_words': 304}