📅  最后修改于: 2023-12-03 15:04:06.723000             🧑  作者: Mango
numpy.arrange() is a highly versatile python numpy function that is used to return evenly spaced values within a given interval.
The function is an implementation of a range function that is utilized within the numpy environment. Therefore, it can be used to create numeric ranges for integer, float, and complex data types.
numpy.arange([start, ]stop, [step, ] dtype=None)
Note that the start
and step
parameters are optional, but if you want to use the step
parameter, you also need to specify the start
parameter.
import numpy as np
np.arange(5)
Output:
array([0, 1, 2, 3, 4])
import numpy as np
np.arange(1, 5, 0.5)
Output:
array([ 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 4.5])
import numpy as np
np.arange(1, 5, dtype=np.complex)
Output:
array([ 1.+0.j, 2.+0.j, 3.+0.j, 4.+0.j])
The numpy.arange()
function is a powerful and flexible tool for creating numeric ranges. Its ability to handle different data types and its support for both integer and float ranges make it a valuable tool for data analysis and scientific computing.