A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/numpy-arrange-in-python/ below:

numpy.arange() in Python - GeeksforGeeks

numpy.arange() in Python

Last Updated : 24 Jan, 2025

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.

Let's understand with a simple example:

Python
import numpy as np 

#create an array 
arr= np.arange(5 , 10)
print(arr)
Syntax of numpy.arange():

numpy.arange([start, ]stop, [step, ]dtype=None, *, like=None)

Parameters of numpy():

Return Type:

Specify Start and Stop

Generate a sequence of integers starting from 5 to 14.

Python
import numpy as np

# Creating a sequence of numbers from 0 to 9
sequence = np.arange(10)
print("Basic Sequence:", sequence)

Output
Basic Sequence: [0 1 2 3 4 5 6 7 8 9]
Floating-Point Step Size

Generate a sequence of floating-point numbers.

Python
import numpy as np 

# Creating a sequence of floating-point numbers from 0 to 1 
# with a step size of 0.2 using np.arange()
sequence = np.arange(0, 1, 0.2)
print("Floating-Point Sequence:", sequence)

Output
Floating-Point Sequence: [0.  0.2 0.4 0.6 0.8]
Combining with Conditional Filtering

Generate a sequence and filter specific values.

Python
import numpy as np 

# Creating a sequence of numbers from 0 to 20 
sequence = np.arange(0, 20, 3)

# Filtering the sequence to include only values greater than 10
filtered = sequence[sequence > 10]
print("Filtered Sequence:", filtered)

Output
Filtered Sequence: [12 15 18]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4