【发布时间】:2020-03-12 13:30:10
【问题描述】:
我目前正在使用一些方法制作自己的矩阵类,并希望实现矩阵乘法。我已经看到它在 numpy 中实现,并想问是否可以在我自己的类中使用它。
【问题讨论】:
标签: python matrix operator-keyword matrix-multiplication
我目前正在使用一些方法制作自己的矩阵类,并希望实现矩阵乘法。我已经看到它在 numpy 中实现,并想问是否可以在我自己的类中使用它。
【问题讨论】:
标签: python matrix operator-keyword matrix-multiplication
通过覆盖__matmul__ 方法(可能还有__rmatmul__)来实现@ 运算符。如果您还想支持@=,请覆盖__imatmul__。
如需更多信息,请阅读Python data model,特别是emulating numeric types 部分。
【讨论】: