numpy.trapz()函數使用複合梯形規則沿給定軸進行積分。
用法: numpy.trapz(y, x = None, dx = 1.0, axis = -1)
參數:
y :[數組]要集成的輸入數組。
x :[數組,可選]與y值相對應的樣本點。如果x為None,則假定采樣點的dx間隔均勻。默認為無。
dx :[標量,可選]當x為None時,采樣點之間的間隔。預設值為1。
axis :[int,可選]積分所沿的軸。
Return :
trapz:[浮點]由梯形法則近似的定積分。
代碼1:
# Python program explaining
# numpy.trapz() function
# importing numpy as geek
import numpy as geek
y = [1, 2, 3, 4]
gfg = geek.trapz( y )
print (gfg)
輸出:
7.5
代碼2:
# Python program explaining
# numpy.trapz() function
# importing numpy as geek
import numpy as geek
y = [1, 2, 3, 4]
x = [5, 6, 7, 8]
gfg = geek.trapz(y, x)
print (gfg)
輸出:
7.5
代碼3:
# Python program explaining
# numpy.trapz() function
# importing numpy as geek
import numpy as geek
y = [1, 2, 3, 4]
gfg = geek.trapz(y, dx = 2)
print (gfg)
輸出:
15.0
相關用法
- Python Wand function()用法及代碼示例
- Python id()用法及代碼示例
- Python oct()用法及代碼示例
- Python sum()用法及代碼示例
- Python ord()用法及代碼示例
- Python str()用法及代碼示例
- Python hex()用法及代碼示例
- Python int()用法及代碼示例
- Python now()用法及代碼示例
- Python cmp()用法及代碼示例
- Python map()用法及代碼示例
- Python tell()用法及代碼示例
- Python dir()用法及代碼示例
- Python reversed()用法及代碼示例
- Python cmath.tan()用法及代碼示例
- Python vars()用法及代碼示例
- Python randint()用法及代碼示例
注:本文由純淨天空篩選整理自sanjoy_62大神的英文原創作品 numpy.trapz() function | Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。