V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
mathzhaoliang
V2EX  ›  Python

请教个问题: Python 的 numpy 中 @ 运算符怎么实现的

  •  
  •   mathzhaoliang ·
    neozhaoliang · 2020-11-18 08:13:50 +08:00 · 2330 次点击
    这是一个创建于 1254 天前的主题,其中的信息可能已经有所发展或是发生改变。

    numpy 里面矩阵乘法可以写成 A @ B,但是我看 Python 语法中标准运算符不包含 @ 呀?它是怎么实现的呢?

    是不是可以自己定义运算符,比如 str1 -- str2 表示将两个字符串 concat 起来?

    5 条回复    2020-11-18 17:05:34 +08:00
    Death
        1
    Death  
       2020-11-18 08:29:40 +08:00 via Android   ❤️ 2
    cigarzh
        2
    cigarzh  
       2020-11-18 08:34:41 +08:00
    谁说 Python 运算符不包含 @的
    wwqgtxx
        3
    wwqgtxx  
       2020-11-18 08:41:09 +08:00 via iPhone
    可能你看的是 py2 时代的语法吧
    szuwl
        4
    szuwl  
       2020-11-18 09:17:10 +08:00
    运算符重载带来的功能呗,Python 的底层就是 C,这有什么好疑惑的
    lithbitren
        5
    lithbitren  
       2020-11-18 17:05:34 +08:00
    https://docs.python.org/zh-cn/3.9/reference/datamodel.html?highlight=matmul#object.__matmul__


    标准语法里有的,矩阵乘法,重载对象的__matmul__方法就行
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5439 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 06:57 · PVG 14:57 · LAX 23:57 · JFK 02:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.