# How to perform element-wise multiplication with mathutils.Vector?

In Blender's I can add/subtract mathutils.Vector without any problems.

vec3 = vec1 - vec2  # OK return a vector


But! It's paint to multiply/divide vector. For example if i multiply vectors i'll get a float.

vec3 = vec1 * vec2  # ERROR return a float


Is there a method to multiply/divide vectors correctly? like vec1.mult(vec2) which exists in other game engines.

• vec1.cross(vec2) returns the cross product vec1 x vec2 and vec1.dot(vec2) returns the dot product vec1 · vec2.
– user7952
Commented Mar 18, 2015 at 21:22
• Note, this is known as "component-wise" or "element-wise" multiplication, see: math.stackexchange.com/questions/32516/… Commented Mar 27, 2015 at 19:47
• @mifth, I'll look into adding element-wise-multiple, there doesn't seem to be a convention for this for object-oriented-Vector API's though, asked here: programmers.stackexchange.com/questions/277583/… Commented Mar 27, 2015 at 20:42
– user7952
Commented Mar 27, 2015 at 20:53
• @SixthOfFour, best move suggestions to the page linked. Commented Mar 28, 2015 at 7:44

After a little bit of research, I concluded that the closest you can get is to use mathutils.Vector.cross() to do a cross multiplication of two vectors, or mathutils.Vector.dot() for dot multiplication; this info was gathered from The API documentation.

However, this doesn't seem to be the behavior you want - it seems you want to multiply the individual components of the vector, for which you can use something similar to this:

def mult(vec, vec2):
temp = []

for x, i in enumerate(vec):
temp.append(i * vec2[x])

return mathutils.Vector(temp)

• Just curious: does anybody know why this is not mentioned in this source? ( docs.blender.org/api/current/mathutils.html ) To make it even more puzzling, it is mentioned in the v2.44 documentation... Am I looking at the wrong package or something? Commented Apr 9, 2020 at 6:17

I am amazed mathutils.Vector class does not support vector scaling by another vector!

This can be for example useful when you get scale vector from matrix decomposition and you want to scale other vectors accordingly.

This is with a generator expression for better performance:

vec3 = Vector(x * y for x, y in zip(vec1, vec2))

• generator-expression is a little nicer then list-comprehension here, edited. Commented Mar 27, 2015 at 19:39
• @ideasman42 good point! Commented Mar 27, 2015 at 20:04