18
$\begingroup$

Blender 2.8 produces the following error whilst multiplying a combination of matrices and vectors

>>> M = Matrix()
>>> v = Vector()
>>> M * v
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
TypeError: Element-wise multiplication: not supported between 'Matrix' and 'Vector' types

>>> v * v
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
TypeError: Element-wise multiplication: not supported between 'Vector' and 'Vector' types

>>> M * M
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
TypeError: Element-wise multiplication: not supported between 'Matrix' and 'Matrix' types
$\endgroup$
0
35
$\begingroup$

Blender 2.8+ Matrix multiplication

The question code method was in place for Blender <=2.79.9. Blender has since adjusted its mathutils module, replacing the asterisk * with the at symbol @, aka the PEP 465 binary operator, for multiplying matrices with vectors.

>>> M = Matrix()
>>> v = Vector()
>>> M @ v
Vector((0.0, 0.0, 0.0))

>>> v @ v
0.0

>>> M @ M
Matrix(((1.0, 0.0, 0.0, 0.0),
        (0.0, 1.0, 0.0, 0.0),
        (0.0, 0.0, 1.0, 0.0),
        (0.0, 0.0, 0.0, 1.0)))

Note using @ will throw the "same type of error" in <= 2.79.9 Replace with * as in question code.

>>> M = Matrix()
>>> M @ M
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
TypeError: unsupported operand type(s) for @: 'Matrix' and 'Matrix'
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.