How to Generate Evenly Spaced Elements in Python

In this article, you will learn how to generate evenly spaced elements in Python. You will be creating 2 arrays of numbers in the range…

The post How to Generate Evenly Spaced Elements in Python appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Ariessa Norramli

In this article, you will learn how to generate evenly spaced elements in Python. You will be creating 2 arrays of numbers in the range of 2 to 10 with different intervals.

Generate Evenly Spaced Elements in Python

In order to generate evenly spaced elements, you can use the numpy.arange() method.

# Import numpy module
import numpy as np

# Generate numbers in the range of 2 to 10, with an interval of 1
print(np.arange(2, 10), "\n") 
# [2 3 4 5 6 7 8 9]
  
# Generate numbers in the range of 2 to 10, with an interval of 2
print(np.arange(2, 10, 2), "\n") 
# [2 4 6 8] 

Note: The numpy.arange() method functions by creating an array of elements with evenly spaced intervals. By default, this method will create an array of elements with an interval of 1.

The post How to Generate Evenly Spaced Elements in Python appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Ariessa Norramli


Print Share Comment Cite Upload Translate Updates
APA

Ariessa Norramli | Sciencx (2021-02-26T10:54:58+00:00) How to Generate Evenly Spaced Elements in Python. Retrieved from https://www.scien.cx/2021/02/26/how-to-generate-evenly-spaced-elements-in-python/

MLA
" » How to Generate Evenly Spaced Elements in Python." Ariessa Norramli | Sciencx - Friday February 26, 2021, https://www.scien.cx/2021/02/26/how-to-generate-evenly-spaced-elements-in-python/
HARVARD
Ariessa Norramli | Sciencx Friday February 26, 2021 » How to Generate Evenly Spaced Elements in Python., viewed ,<https://www.scien.cx/2021/02/26/how-to-generate-evenly-spaced-elements-in-python/>
VANCOUVER
Ariessa Norramli | Sciencx - » How to Generate Evenly Spaced Elements in Python. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/02/26/how-to-generate-evenly-spaced-elements-in-python/
CHICAGO
" » How to Generate Evenly Spaced Elements in Python." Ariessa Norramli | Sciencx - Accessed . https://www.scien.cx/2021/02/26/how-to-generate-evenly-spaced-elements-in-python/
IEEE
" » How to Generate Evenly Spaced Elements in Python." Ariessa Norramli | Sciencx [Online]. Available: https://www.scien.cx/2021/02/26/how-to-generate-evenly-spaced-elements-in-python/. [Accessed: ]
rf:citation
» How to Generate Evenly Spaced Elements in Python | Ariessa Norramli | Sciencx | https://www.scien.cx/2021/02/26/how-to-generate-evenly-spaced-elements-in-python/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.