def linspace(start, stop, num, endpoint=True):
    """ 
    Generate linear space. This is sometimes more appropriate than
    using `range`.

    Parameters
    ----------
    start : float
        The starting value of the sequence.
    stop : float
        The end value of the sequence.
    num : int
        Number of samples to generate.
    endpoint : bool, optional
        If True (default), the endpoint is included in the linear space.

    Yields
    ------
    val : float

    See also
    --------
    numpy.linspace : generate linear space as a dense array.
    """
    if endpoint:
        num -= 1
    step = (stop - start) / num
    val = start
    for _ in range(num):
        yield val
        val += step
    if endpoint:
        yield stop
