def lengths(x, lower_field='start', upper_field='stop'):
    """
    Calculate lengths of intervals in an array.

    :param x: array of intervals
    :type x: :class:`numpy.array`
    :param lower_field: field name of lower bound of intervals
    :type lower_field: str
    :param upper_field: field name of upper bound of intervals
    :type upper_field: str

    :return: an array of interval lengths
    :rtype: :class:`numpy.array`[int]
    """
    return 1 + x[upper_field] - x[lower_field]