關(guān)于tensorflow函數(shù)tf.scan簡易解讀

tf.scan(fn, elems, initializer=None, parallel_iterations=10, back_prop=True, swap_memory=False, infer_shape=True, name=None)

具體參數(shù)定義可以參見官網(wǎng),這里撿最常見的形式來說,常用函數(shù)形式為tf.scan(fn, elems, initializer=None)
函數(shù)說明:scan on the list of tensors unpacked from elems on dimension 0.
f(n)以elems的第一維度的變量list作函數(shù)計算直到遍歷完整個elems
關(guān)于 initializer的說明為:
If no initializer is provided, the output structure and dtypes of fn are assumed to be the same as its input; and in this case, the first argument of fn must match the structure of elems.
If an initializer is provided, then the output of fn must have the same structure as initializer; and the first argument of fn must match this structure.
也就是說當(dāng)initializer給定的時候,fn的輸出結(jié)構(gòu)必須和initializer保持一致,且fn的第一個參變量也必須和該結(jié)構(gòu)一致。而如果該參數(shù)沒有給定的時候初始化默認和x[0]的維度保持一致。

  設(shè)函數(shù)為f,
  x = [u(0),u(1),...,u(n)]
  y = tf.scan(f,x,initializer=v(0))
  此時f的參數(shù)類型必須是(v(0),x),f的輸出必須和v(0)保持一致,整個計算過程如下:
  v(1)=f(v(0),u(0))
  v(2)=f(v(1),u(1))
  ....
  v(n+1)=f(v(n),u(n))
  y=v(n+1)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • pyspark.sql模塊 模塊上下文 Spark SQL和DataFrames的重要類: pyspark.sql...
    mpro閱讀 9,920評論 0 13
  • Chapters: Enumerations - Advanced Operators Excerpt From:...
    碧波浮沉閱讀 709評論 0 1
  • tensorflow開發(fā)API 架構(gòu) Modules app module: Generic entry poin...
    sennchi閱讀 1,443評論 0 2
  • 我是一個編輯,我學(xué)的是理工科,所以我并不是文藝青年,如果說真要有什么情懷的話,我希望能夠普及科學(xué)的精神和素養(yǎng),誰都...
    MIKA0907閱讀 188評論 0 1
  • 2019年11月20日 星期三 晴 今日政治老師突然說到一個問題時,我便開始了聯(lián)想,有時候我覺得自己腦洞挺大的,...
    以讀書為樂閱讀 377評論 0 0

友情鏈接更多精彩內(nèi)容