![]() |
VOOZH | about |
numpy.arange() function creates an array of evenly spaced values within a given interval. It is similar to Python's built-in range() function but returns a NumPy array instead of a list.
Example: This example creates a NumPy array containing values from 5 to 9 using numpy.arange().
[5 6 7 8 9]
numpy.arange(start, stop, step, dtype=None)
Parameters:
Return Type: array of evenly spaced values.
This example shows how np.arange() generates a sequence of integers by specifying only the stop value. By default, the sequence starts from 0 and increases by 1 until the stop value is reached (excluding it).
Basic Sequence: [0 1 2 3 4 5 6 7 8 9]
Explanation: np.arange(10) creates values starting from 0 up to 9.
np.arange() can also generate sequences with floating-point values by specifying a decimal step size.
Floating-Point Sequence: [0. 0.2 0.4 0.6 0.8]
Explanation: sequence starts at 0 and increases by 0.2 and value 1 is excluded from the output.
NumPy allows combining arange() with conditional filtering to extract specific values from a generated sequence.
Filtered Sequence: [12 15 18]
Explanation: