import numpy as np
def generate_evenly_spaced(start: float, stop: float, k: int, include_endpoint: bool = True):
"""
Generate k evenly spaced float values between start and stop using numpy.linspace.
:param start: Starting value of the sequence.
:param stop: Ending value of the sequence.
:param k: Number of values to generate (must be >= 1).
:param include_endpoint: Whether to include the stop value in the sequence.
:return: NumPy array of evenly spaced floats.
"""
# Input validation
if not isinstance(start, (int, float)) or not isinstance(stop, (int, float)):
raise TypeError("start and stop must be numeric values.")
if not isinstance(k, int) or k < 1:
raise ValueError("k must be a positive integer.")
# Generate evenly spaced values
values = np.linspace(start, stop, k, endpoint=include_endpoint, dtype=float)
return values
if __name__ == "__main__":
start_val = 0.0
stop_val = 5.0
k_values = 7
result = generate_evenly_spaced(start_val, stop_val, k_values)
print(f"{k_values} evenly spaced values from {start_val} to {stop_val}:")
print(result)
'''
run:
7 evenly spaced values from 0.0 to 5.0:
[0. 0.83333333 1.66666667 2.5 3.33333333 4.16666667
5. ]
'''