【问题标题】:Python: How to implement the @ operator for my own class [closed]Python:如何为我自己的类实现@运算符[关闭]
【发布时间】:2020-03-12 13:30:10
【问题描述】:

我目前正在使用一些方法制作自己的矩阵类,并希望实现矩阵乘法。我已经看到它在 numpy 中实现,并想问是否可以在我自己的类中使用它。

【问题讨论】:

    标签: python matrix operator-keyword matrix-multiplication


    【解决方案1】:

    通过覆盖__matmul__ 方法(可能还有__rmatmul__)来实现@ 运算符。如果您还想支持@=,请覆盖__imatmul__。

    如需更多信息,请阅读Python data model,特别是emulating numeric types 部分。

    【讨论】:

      猜你喜欢
      • 2016-02-29
      • 2017-10-26
      • 2020-09-06
      • 2015-04-30
      • 2018-04-24
      • 2013-08-08
      • 1970-01-01
      • 2017-09-08
      • 2012-11-24
      相关资源
      最近更新 更多