[Python] Is there really an @ operator in Python to calculate dot product? Why doesn't it work...

Discussão em 'Python' iniciado por Stack, Agosto 27, 2025.

  1. Stack

    Stack Membro Participativo

    Is this answer correct?


    In Python 3.5, there is a new operator for the dot product, so you can write a = A @ B instead of a = numpy.dot(A, B)
    ​

    — Henri Andre, on "What is the pythonic way to calculate dot product?"

    It does not seem to work for me.

    $ python3
    Python 3.6.1 (default, Apr 4 2017, 09:40:21)
    [GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> a = [1, 2, 3]
    >>> b = [4, 5, 6]
    >>> a @ b
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    TypeError: unsupported operand type(s) for @: 'list' and 'list'


    But the linked answer has received 6 upvotes, so I must be missing something. Can you provide a complete example that shows how to use the @ operator to calculate a dot product?

    Continue reading...

Compartilhe esta Página