def _value_to_class(class_dict, value):
    """ Map numpy array values using a dictionary.
    Convenience function for dictionaries that are keyed on tuples or integers.

    Used to map integers (numpy arrays of integers, shape (3,)) to integers.
    These integers enumerate the class that a pixel belongs to.

    :param class_dict: A mapping of tuples of integers (i.e. RGB pixels) to integers
    :type class_dict: dict
    :param value: The key used to index the class_dict.
    :type value: numpy.ndarray

    :raises ValueError: If the value has a shape with 2 or more axes.

    :returns: A mapping per class_dict, or 0 if that value is not available.
    :rtype: Anything

    >>> _value_to_class(
    ...     {(1,2,3) : 'some_class', 789 : 'another_class'},
    ...      np.array([1,2,3]))
    'some_class'

    >>> _value_to_class(
    ...     {(1,2,3) : 'some_class', 789 : 'another_class'},
    ...      np.array(789))
    'another_class'
    """
    # This was written when I was a baby. There's probably a better way to do
    # this using dictionaries.

    # E.g. If the shape of the array = (3,), e.g. np.array([255, 255, 255])
    if len(value.shape) == 1:
        if tuple(value) in class_dict.keys():
            return class_dict[tuple(value)]
        else:
            return 0
    # E.g. if the shape of the array = (), e.g. np.array(12345)
    elif len(value.shape) == 0:
        if value in class_dict.keys():
            return class_dict[value]
        else:
            return 0
    else:
        raise ValueError