Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
numpy
arange()
communitycreator

What is the arange() function from NumPy in Python?

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

Overview

The arange() function in Python returns evenly spaced values within a given interval from NumPy.

Syntax

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

Parameter values

The arange() function takes the following parameter values:

  • start: this represents the start of the interval. The default value for start is 0. This is optional.
  • stop: this represents the end of the interval. The interval does not include this value.
  • step: this represents the spaces between the values. This is optional.
  • dtype: this represents the data type of the output array.
  • like: this represents the array-like object or prototype.

Return value

The arange() function returns an array of evenly spaced values.

Code example

from numpy import arange
# creating the array
my_array = arange(1, 11, 1, dtype = int)
print(my_array)
Implementing the nump.arange() function

Code explanation

  • Line 1: We import the arange function from numpy library.
  • Line 4: Using the arange() function, we create an array to start at 1, stop at 11 (11 not included), with a step size of 1, and with an int data type. The result is assigned to the variable my_array.
  • Line 5: We print the array my_array.

RELATED TAGS

python
numpy
arange()
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring