我在别人的项目中遇到了以下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
提交
取消