亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

奇怪的python“嵌套”for循環

奇怪的python“嵌套”for循環

青春有我 2021-11-02 20:32:10
我在別人的項目中遇到了以下for循環,以前從未見過這樣的語法。它有點像嵌套 for 循環的突變,但不完全是。無論如何,我應該如何解釋這行代碼?或者我怎樣才能展開這個循環?for a in [np.transpose(np.array([list(B['v'][x]) + [0,1] for x in (face[0], face[1], face[2])]))  for face in B['shape']]:     facets.extend([np.do(r) * scale for x in inflate(a)])
查看完整描述

1 回答

?
泛舟湖上清波郎朗

TA貢獻1818條經驗 獲得超3個贊

np.array表達式的內容是:


[list(B['v'][x]) + [0,1] for x in (face[0], face[1], face[2])]

參考上面的*,正在迭代的外部列表的內容是:


[np.transpose(np.array(*)) for face in B['shape']]

將每個列表推導式轉換為 for 循環:


for face in B['shape']:

    y = [] # temporary variable

    for x in (face[0], face[1], face[2]):

        y.append(list(B['v'][x]) + [0, 1])


    # outer loop variable

    a = np.transpose(np.array(y)) 


    z = [] # temporary variable

    for x in inflate(a):

        z.append(np.do(r) * scale)

    facets.extend(z)


查看完整回答
反對 回復 2021-11-02
  • 1 回答
  • 0 關注
  • 204 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號