运算符@在python中的含义是什么

悖论

我正在阅读某人的代码,其中出现了运算符“@”(实际上,我什至不确定 @ 是否是运算符)。

我四处寻找,却找不到任何线索。我想这是一些高级用法。

下面是一些示例代码:

hidden = self.adj_norm @ tf.sparse_tensor_dense_matmul(hidden, w) + b

hidden = self.adj_norm @ hidden @ w + b

final_output = self.adj_norm @ tf.sparse_tensor_dense_matmul(final_output, w) + b

final_output = self.adj_norm @ final_output @ w + b

有人可以解释或提供一些参考资料,我可以检查“@”的用法吗?

亚什·克里山

大多数情况下 @ 用作装饰器。但是,在您的情况下,它似乎用于矩阵乘法。

在python矩阵乘法中,x @ y调用x.__matmul__(y)或:

x @ y
#equivalent to

dot(x, y)
and

x @= y
#equivalent to

x = dot(x, y)

Dot 是 Numpy 和 x 和 y 中的矩阵乘法函数。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章