numpy.ma.ediff1d()函數返回數組的連續元素之間的差異。
用法:numpy.ma.ediff1d(arr, to_end = None, to_begin = None)
Parameters:
arr:[數組]輸入數組。
to_end:[數組,可選]在返回的差異末尾附加的數字。
to_begin:[數組,可選]在返回的差異的開頭加上數字。
返回:返回數組的連續元素之間的差。
代碼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)
輸出:
[ 2 3 -4 8]
代碼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)
輸出:
[-23 0 2 3 -4 8 25]
相關用法
- Python Wand function()用法及代碼示例
- Python Sorted()用法及代碼示例
- Python Numbers choice()用法及代碼示例
- Python Tkinter askopenfile()用法及代碼示例
- Python ord()用法及代碼示例
- Python round()用法及代碼示例
- Python id()用法及代碼示例
- Python vars()用法及代碼示例
注:本文由純淨天空篩選整理自code_hunt大神的英文原創作品 numpy.ma.ediff1d() function in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。