numpy - arange

By xngo on April 2, 2020

In Python, you can easily generate a list of numbers using numpy.arange([start, ]stop, [step, ]dtype=None) function. The example below will create an array of numbers between 1 and 10. And, each number is spaced 1 unit(step) apart.

import numpy as np
range = np.arange(start = 1, stop = 10, step = 1, dtype='int')
print(range)

Output

[1 2 3 4 5 6 7 8 9]

Github

  • https://github.com/xuanngo2001/python-examples/blob/master/numpy/numpy-arange.py

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.