Friday, September 26, 2025
HomeLanguagesPython | Numpy np.ediff1d() method

Python | Numpy np.ediff1d() method

With the help of np.ediff1d() method, we can get the 1D array of differences between two consecutive elements by using np.ediff1d() method.

Syntax : np.ediff1d(array)
Return : Return 1D array having differences of consecutive elements.

Example #1 :
In this example we can see that by using np.ediff1d() method, we are able to get the 1D array of consecutive differences of the elements of an array using this method.




# import numpy
import numpy as np
  
# using np.ediff1d() method
arr = np.array([1, 2, 3, 5, 7, 11])
gfg = np.ediff1d(arr)
  
print(gfg)


Output :

[1 1 2 2 4]

Example #2 :




# import numpy
import numpy as np
  
# using np.ediff1d() method
arr = np.array([1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47])
gfg = np.ediff1d(arr)
  
print(gfg)


Output :

[1 1 2 2 4 2 4 2 4 6 2 6 4 2 4]

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32321 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6690 POSTS0 COMMENTS
Nicole Veronica
11857 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11911 POSTS0 COMMENTS
Shaida Kate Naidoo
6802 POSTS0 COMMENTS
Ted Musemwa
7072 POSTS0 COMMENTS
Thapelo Manthata
6761 POSTS0 COMMENTS
Umr Jansen
6768 POSTS0 COMMENTS