📜  Python中的 numpy.ma.ediff1d()函数

📅  最后修改于: 2022-05-13 01:54:35.440000             🧑  作者: Mango

Python中的 numpy.ma.ediff1d()函数

numpy.ma.ediff1d()函数返回数组的连续元素之间的差异。

代码#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)


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)


输出:

[ 2  3 -4  8]

代码#2:

蟒蛇3

# 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)

输出:

[-23 0 2 3 -4 8 25]