We can use the numpy.arange()
function to create an array of equally spaced values within a given range. The function takes three arguments:
Here's an example:
main.py137 chars8 lines
If we omit the step
argument, it defaults to 1:
main.py154 chars8 lines
We can also use the numpy.linspace()
function to create an array of equally spaced values with a specified number of elements. The function takes three arguments:
Here's an example:
main.py164 chars8 lines
Note that the stop
argument is inclusive in numpy.linspace()
, unlike in numpy.arange()
.
gistlibby LogSnag