Technology3 min read

numpy.arange() method

Abhishek Ahlawat

By Abhishek Ahlawat โ€” Recently

Founder of StudyTonight and a MERN fullstack developer. Writes about JavaScript, web development, Linux, and tech.

Summarize this article using AI

How it works ?

Returns an array with evenly spaced elements as per the interval.

The interval mentioned is half opened i.e. [Start, Stop).

Length of array being generated = Ceil((Stop - Start) / Step)


Parameters : arange(start, stop, step, dtype)

  • start : [optional] start range of interval . By default start = 0
  • stop : end range of interval.
  • step : [optional] step size of interval. By default step size = 1
  • dtype : type of output array[can be int, flaot, complex]

Code :

# Working of 
# numpy.arange method
 
import numpy as geek
 
# reshape(2, 2) means 2D matrix of size 2 X 2 
print("Array 1 : \n", geek.arange(4).reshape(2, 2), "\n")
 
print("Array 2 : ", geek.arange(4, 10), "\n")
 
print("Array 3 : ", geek.arange(4, 20, 3))

Output :

Array 1 : 
 [[0 1]
 [2 3]] 

Array 2 :  [4 5 6 7 8 9] 

Array 3 :  [ 4  7 10 13 16 19]
For an query contact me at : https://www.linkedin.com/in/mohit-gupta-003512116/

Spotted something outdated or wrong?

Liked this? See more StudyTonight posts in Google results.

Add StudyTonight as a preferred source
Next questLIVE OPSStep 2 / 3

Practice real incidents in the browser

System Design Ops โ€” put out fires, ship fixes, and stack XP. Reading done. Time to play.

Play System Design
  • +XP

    Every sim

  • Incidents

    Live ops

  • Ranks

    Climb up

Read next