最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python?torch.fft.rfft()函數(shù)用法示例代碼

 更新時(shí)間:2022年04月14日 12:02:10   作者:Oxygen?H2O  
大家應(yīng)該都知道新舊版的torch中的傅里葉變換函數(shù)在定義和用法上有所不同,下面這篇文章主要給大家介紹了關(guān)于Python?torch.fft.rfft()函數(shù)用法的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下

在新舊版的torch中的傅里葉變換函數(shù)在定義和用法上存在不同,記錄一下。

1、舊版

fft = torch.rfft(input, 2, normalized=True, onesided=False)
#  input 為輸入的圖片或者向量,dtype=torch.float32,size比如為[1,3,64,64]
#  signal_ndim(int):The number of dimensions in each signal,can only be 1、2、3
#  normalized(bool,optional):controls wheather to return normallized results. Default:False
#  onesided(bool,optional):controls whether to return half of results to avoid redundancy.Default:True 

上面例子中圖像中 singal_ndim = 2 ,是因?yàn)檩斎雸D像是2維的。

1.7之后的版本中,如果要用 oneside output,則改用torch.fft.rfft();如果要用two-side output,則改用torch.fft.fft()

input= torch.arange(4)
fft = torch.rfft(input, 2, normalized=True, onesided=False)

2、新版

一維離散傅里葉變換

torch.fft.rfft(input,n=None,dim=-1,norm=None) --> Tensor
# input:Tensor
# n(int,optional):Output signal length. This determines the length of the
        output signal. 
# dim(int, optional): The dimension along which to take the one dimensional real IFFT.
# norm (str, optional): Normalization mode.

二維離散傅里葉變換 

torch.fft.rfft2(input, s=None, dim=(-2, -1), norm=None, *, out=None) -> Tensor
input (Tensor): the input tensor
s (Tuple[int], optional): Signal size in the transformed dimensions.
dim (Tuple[int], optional): Dimensions to be transformed.
norm (str, optional): Normalization mode.

高維離散傅里葉變換 

rfftn(input, s=None, dim=None, norm=None, *, out=None) -> Tensor
input (Tensor): the input tensor
s (Tuple[int], optional): Signal size in the transformed dimensions.
dim (Tuple[int], optional): Dimensions to be transformed.
norm (str, optional): Normalization mode. For the forward transform

3、新舊版對(duì)比

import torch
input = torch.rand(1,3,32,32)
 
# 舊版pytorch.rfft()函數(shù)
fft = torch.rfft(input, 2, normalized=True, onesided=False)
 
# 新版 pytorch.fft.rfft2()函數(shù)
output = torch.fft.fft2(input, dim=(-2, -1))
output = torch.stack((output.real, output_new.imag), -1)
 
ffted = torch.rfft(input, 1, onesided=False) to ffted = torch.view_as_real(torch.fft.fft(input, dim=1))
and
iffted = torch.irfft(time_step_as_inner, 1, onesided=False) to
iffted = torch.fft.irfft(torch.view_as_complex(time_step_as_inner), n=time_step_as_inner.shape[1], dim=1)

補(bǔ)充:使用numpy模擬torch.fft.fft拯救paddle

import numpy as np
import torch
import paddle
def paddle_fft(x,dim=-1):
    if dim==-1:
        return  paddle.to_tensor(np.fft.fft(x.numpy()))
    else:
        shape= [i for i in range(len(x.shape))]
        shape[dim],shape[-1]=shape[-1],shape[dim]

        x=np.transpose(np.fft.fft(np.transpose(x.numpy(), shape)),shape)
        return paddle.to_tensor(x)





if __name__ == '__main__':
    data=paddle.to_tensor(np.array([[[1, 4, 3], [1, 2, 3]], [[1, 2, 3], [1, 2, 3]]]))

    paddle_f_d=paddle_fft(paddle_fft(data,-1),-2)
    torch_f_d =paddle_fft(torch.fft.fft(torch.Tensor(data.numpy()),dim=-1),-2)
    print(paddle_f_d.numpy())
    print(torch_f_d.numpy())

總結(jié)

到此這篇關(guān)于Python torch.fft.rfft()函數(shù)用法的文章就介紹到這了,更多相關(guān)torch.fft.rfft()函數(shù)用法內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 如何使用Python?繪制瀑布圖

    如何使用Python?繪制瀑布圖

    這篇文章主要介紹了如何使用Python?繪制瀑布圖,我們一起了解瀑布圖的重要性,以及如何使用不同的繪圖庫(kù)繪制瀑布圖。瀑布圖是一種二維圖表,專(zhuān)門(mén)用于了解隨著時(shí)間或多個(gè)步驟或變量的增量正負(fù)變化的影響,下文更多詳細(xì)內(nèi)容需要的小伙伴可以參考一下
    2022-05-05
  • 使用Python解析Chrome瀏覽器書(shū)簽的示例

    使用Python解析Chrome瀏覽器書(shū)簽的示例

    這篇文章主要介紹了使用Python解析Chrome瀏覽器書(shū)簽的示例,幫助大家更好的理解和使用python,感興趣的朋友可以了解下
    2020-11-11
  • pytest官方文檔解讀fixtures的autouse

    pytest官方文檔解讀fixtures的autouse

    這篇文章主要為大家介紹了pytest官方文檔解讀fixtures的autouse,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-06-06
  • Python中對(duì)字典的幾個(gè)處理方法分享

    Python中對(duì)字典的幾個(gè)處理方法分享

    這篇文章主要介紹了Python中對(duì)字典的幾個(gè)處理方法分享,文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,感興趣的小伙伴可以參考一下
    2022-08-08
  • Python學(xué)習(xí)筆記之線程

    Python學(xué)習(xí)筆記之線程

    這篇文章主要介紹了Python線程詳解,本文詳細(xì)講解了線程方方面面的知識(shí),如線程基礎(chǔ)知識(shí)線程狀態(tài)、線程同步(鎖)、線程通信(條件變量)等內(nèi)容,需要的朋友可以參考下
    2021-11-11
  • Python發(fā)布 Web應(yīng)用的常見(jiàn)方法及詳細(xì)步驟

    Python發(fā)布 Web應(yīng)用的常見(jiàn)方法及詳細(xì)步驟

    本文詳細(xì)介紹了Python發(fā)布Web應(yīng)用的常見(jiàn)方法,包括本地開(kāi)發(fā)、Nginx+Gunicorn部署、Heroku一鍵部署、Docker容器化部署和Serverless部署,并提供了每種方法的詳細(xì)步驟和優(yōu)缺點(diǎn)對(duì)比,需要的朋友可以參考下
    2025-03-03
  • python 裝飾器重要在哪

    python 裝飾器重要在哪

    這篇文章主要介紹了python 裝飾器重要在哪,幫助大家更好的理解和使用python,感興趣的朋友可以了解下
    2021-02-02
  • django中顯示字符串的實(shí)例方法

    django中顯示字符串的實(shí)例方法

    在本篇文章里小編給大家整理了一篇關(guān)于django中顯示字符串的實(shí)例方法,有興趣的朋友們可以跟著學(xué)習(xí)參考下。
    2021-03-03
  • python常見(jiàn)模塊與用法

    python常見(jiàn)模塊與用法

    這篇文章主要介紹了python常見(jiàn)模塊與用法,文中有非常詳細(xì)的代碼示例,對(duì)正在學(xué)習(xí)python的小伙伴們有一定的幫助,需要的朋友可以參考下
    2021-04-04
  • Python列表排序 list.sort方法和內(nèi)置函數(shù)sorted用法

    Python列表排序 list.sort方法和內(nèi)置函數(shù)sorted用法

    這篇文章主要介紹了Python列表排序 list.sort方法和內(nèi)置函數(shù)sorted用法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2021-03-03

最新評(píng)論

保定市| 油尖旺区| 洛宁县| 龙井市| 马鞍山市| 德兴市| 深水埗区| 宽城| 额尔古纳市| 应用必备| 建昌县| 武夷山市| 东乌| 隆昌县| 盐山县| 蒙山县| 方正县| 绍兴县| 延吉市| 乌苏市| 深圳市| 武宁县| 正阳县| 太康县| 大兴区| 临高县| 车险| 淮北市| 资源县| 玉环县| 黄浦区| 新巴尔虎左旗| 伽师县| 恩施市| 彭阳县| 留坝县| 黔西| 福鼎市| 石门县| 西城区| 肃北|