Projects/numpy_linspace_function.py
2025-09-12 20:37:36 -07:00

27 lines
982 B
Python

import numpy as np
# Generating 5 equally spaced values between 0 and 1 (inclusive)
array_1 = np.linspace(0, 1, 5)
print('Example 1:', array_1)
# Generating 7 equally spaced values between -1 and 1 (inclusive)
array_2 = np.linspace(-1, 1, 7)
print('Example 2:', array_2)
array_2 = np.linspace(-1, 1, 7)
print(f"Example 2:", {array_2.dtype.name})
#setting endpoint to False
array_3 = np.linspace(0, 1, 5, endpoint=False)
# Generating 5 equally spaced values between 0 and 1 (inclusive)
array_inclusive = np.linspace(0, 1, 5)
print('Endpoint = True:', array_inclusive)
# Generating 5 equally spaced values between 0 and 1 (exclusive)
array_exclusive = np.linspace(0, 1, 5, endpoint=False)
print('Endpoint = False:', array_exclusive)
# Create an array of even numbers from 2 to 21 exclusive
even_numbers = np.arange(2, 21, 2)
# Create an array of 10 equally spaced numbers between 5 and 6 exclusive
samples = np.linspace(5, 6, 10, endpoint=False)
print(even_numbers)
print(samples)