【问题标题】:What dose the operator @ mean in python [duplicate]运算符@在python中的含义是什么[重复]
【发布时间】:2019-09-12 06:29:30
【问题描述】:

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

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

下面是一些示例代码:

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 python-3.x


【解决方案1】:

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

在 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 中的矩阵乘法函数。

【讨论】:

  • x@y 不等于 np.dot(x, y) dot 和 matmul 是不同的操作
  • 是python 3独有的吗?我正在使用 python 2.7
猜你喜欢
  • 1970-01-01
  • 2015-07-16
  • 2020-05-26
  • 1970-01-01
  • 2015-10-29
  • 2021-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多