當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python scipy.fft()用法及代碼示例

借助於scipy.fft()方法,我們可以通過傳遞簡單的一維numpy數組來計算快速傅裏葉變換,並且它將使用此方法返回變換後的數組。

快速傅立葉變換

用法:scipy.fft(x)

Return:返回轉換後的數組。

範例1:

在此示例中,我們可以看到,通過使用scipy.fft()方法,我們可以通過傳遞數字序列並返回轉換後的數組來計算快速傅立葉轉換。



Python3

# import scipy and numpy 
import scipy 
import numpy as np 
  
x = np.array(np.arange(10)) 
# Using scipy.fft() method 
gfg = scipy.fft(x) 
  
print(gfg)

輸出:

[45. +0.j         -5.+15.38841769j -5. +6.8819096j  -5. +3.63271264j

-5. +1.62459848j -5. +0.j         -5. -1.62459848j -5. -3.63271264j

-5. -6.8819096j  -5.-15.38841769j]

範例2:

Python3

# import scipy and numpy 
import scipy 
import numpy as np 
  
x = np.array(np.arange(5)) 
# Using scipy.fft() method 
gfg = scipy.fft(x) 
  
print(gfg)

輸出:

[10. +0.j         -2.5+3.4409548j  -2.5+0.81229924j -2.5-0.81229924j

-2.5-3.4409548j ]

相關用法


注:本文由純淨天空篩選整理自Jitender_1998大神的英文原創作品 scipy.fft() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。