Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why documentation etc. use @ in place of * for multiplication

Why many documentations and blog posts use @ in place of * (multiplication operator) in python.
Here is an example. They use C@x instead of c*x (also found in the next lines in the page). Is @ used to say it is vector multiplication etc.?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

They write it like that because the underlying objects are matrices and/or vectors, not scalars.

The operator @ indicates a matrix multiplication, and hooks into the datamodel __matmul__, which has a different behaviour to * operation i.e. __mul__.

The most common case you will see is with numpy ndarrays, where @ is matrix multiplication and * is element-wise multiplication:

>>> A = np.arange(4).reshape(2,2)
>>> A
array([[0, 1],
       [2, 3]])
>>> A @ A
array([[ 2,  3],
       [ 6, 11]])
>>> A * A
array([[0, 1],
       [4, 9]])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading