Thursday, September 4, 2025
HomeLanguagesnumpy.ma.ediff1d() function in Python

numpy.ma.ediff1d() function in Python

numpy.ma.ediff1d() function return the differences between consecutive elements of an array.

Syntax : numpy.ma.ediff1d(arr, to_end = None, to_begin = None) 

Parameters : 
arr : [array_like] Input array. 
to_end : [array_like, optional] Number to append at the end of the returned differences. 
to_begin : [array_like, optional] Number to prepend at the beginning of the returned differences. 

Return : Return the differences between consecutive elements of an array. 

Code #1:

Python3




# Python program explaining
# numpy.ma.ediff1d() function
  
# importing numpy as geek
import numpy as geek
  
arr = geek.array([3, 5, 8, 4, 12])
  
gfg = geek.ma.ediff1d(arr)
  
print(gfg)


Output:

[ 2  3 -4  8]

Code #2:

Python3




# Python program explaining
# numpy.ma.ediff1d() function
  
# importing numpy as geek
import numpy as geek
  
arr = geek.array([3, 5, 8, 4, 12])
  
gfg = geek.ma.ediff1d(arr, to_begin=geek.array([-23, 0]), to_end=25)
  
print(gfg)


Output:

[-23 0 2 3 -4 8 25]
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32261 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6747 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6695 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS