我在別人的項目中遇到了以下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)
添加回答
舉報
0/150
提交
取消