日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

pythonloop循环结构_python - tensorflow,tf.while_loop:这两个结构没有相同的嵌套结构 - SO中文参考 - www.soinside.com...

發布時間:2025/4/16 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 pythonloop循环结构_python - tensorflow,tf.while_loop:这两个结构没有相同的嵌套结构 - SO中文参考 - www.soinside.com... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我試圖構建一個嵌套循環,用于創建一個2-dim零矩陣來解決LCS問題(動態編程)。這稍后用于計算Rouge-L得分(輸入是張量,而不是字符串),但總是出錯提高ValueError: The two structures don't have the same nested structure.

我檢查了一些類似的問題,我修改了一些代碼,但它仍然無法工作(我在這里提出的代碼是最終代碼):

我改變了shape_invariants。我現在使用len(內部)來動態獲取內部的形狀。

還是shape_invariants,我現在將1改為0(shape_invariants中的第一個參數)。我認為標量的形狀是1,但我在github上檢查了一些源代碼,我發現它全部使用0。

# the origin code is below, in which sub and string are both string(type), len_sub and len_string are both int:

lengths = [[0 for i in range(0,len_sub+1)] for j in range(0,len_string+1)]

# but in the new code that I need, the sub and string are both tensor, so I code like this:

len_string = tf.shape(string)[0]

len_sub = tf.shape(sub)[0]

def _add_zeros(i,inner):

inner.append(0)

return i+1, inner

def _add_inners(j, lengths):

i=0

inner = []

_, inner = tf.while_loop(

cond=lambda i,*_: i<=len_sub,

body=_add_zeros,

loop_vars=[i,inner],

shape_invariants=[0,len(inner)])

lengths.append(inner)

return j+1, lengths

lengths = []

j = 0

_, lengths = tf.while_loop(

cond=lambda j,*_: j<=len_string,

body=_add_inners,

loop_vars=[j,lengths],

shape_invariants=[0,len(lengths)])

ValueError: The two structures don't have the same nested structure.

First structure: type=list str=[0, []]

Second structure: type=list str=[0, 0]

More specifically: Substructure "type=list str=[]" is a sequence, while substructure "type=int str=0" is not

Entire first structure:

[., []]

Entire second structure:

[., .]

我不知道為什么會出錯。如果你能提供幫助,我會很感激的。

總結

以上是生活随笔為你收集整理的pythonloop循环结构_python - tensorflow,tf.while_loop:这两个结构没有相同的嵌套结构 - SO中文参考 - www.soinside.com...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。