2
$\begingroup$

I've been trying to figure out what the @ in the following code does:

T_world2bcam = -1*R_world2bcam @ cam.location

where R_world2bcam is a 3x3 Matrix and cam.location is a Vector.

The code is from this blender answer.

I have searched for this in the python docs, numpy docs, blender docs but was not able to find anything. Please excuse me, if this is a dumb answer, but I'm quite frustrated not being able to find anything about that ominous @.

$\endgroup$
1
  • $\begingroup$ In this case it's matrix-vector multiplication. It also does matrix-matrix multiplication and quaternion-quaternion multiplication. $\endgroup$
    – scurest
    Feb 28, 2022 at 19:44

1 Answer 1

2
$\begingroup$

Let me introduce you to PEP 465 titled "A dedicated infix operator for matrix multiplication". Introduced in 2014 and available in Python since version 3.5, the @ operator is, as scurest mentioned in a comment, a

binary operator to be used for matrix multiplication

In math, you can multiply any two matrices $X$ and $Y$ provided that the second dimension of $X$ is the same as the first dimension of $Y$, that is, so long as $X$ is an $m$ x $n$ matrix and $Y$ is an $n$ x $o$ matrix. The result will be a $m$ x $o$ matrix. In math this is represented usually with the simple multiply operator $X * Y$ but for reasons described in PEP 465, it was decided to adopt the @ character in Python to distinguish matrix multiply, which is not commutative, from scaler multiply, which in the case of two scalers is commutative.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .