25
$\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

2 Answers 2

44
$\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$
0
$\begingroup$

If @ or * that doesn't solve it, make sure you have imported mathutils AFTER bpy in your python file. thus:

import bpy
import mathutils
$\endgroup$

You must log in to answer this question.

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