# How can I multiply or swap the individual coordinates of a Vector?

I have two vectors that I would like to print to a file but before that I would like to multiply x and y in the first with -1 so instead of Vector((5, -10, 0)) it should be ((-5, 10, 0)) and in the second I would like to change order of y and z from Vector((0.0, 0.5, 1.0)) to Vector((0.0, 1.0, 0.5)).

Any ideas?

• its simple.(its mainly a python question) 1) a = Vector((5, -10, 0)) 2) a.z, a.y = a.y, a.z 3) a = -a 4) print to file Commented Jun 21, 2022 at 14:37

## 1 Answer

First one is simple, multiply by (-1,-1,1):

a = Vector((5,-10,0))
print(a * Vector((-1,-1,1)))
# output: Vector((-5.0, 10.0, 0.0))


Second - rearrange it like this:

b =  Vector((0.0, 0.5, 1.0))
print(Vector((b.x, b.z, b.y)))
# output: Vector((0.0, 1.0, 0.5))

• Thanks a lot. I get NameError: name 'Vector' is not defined, is there some library that I miss? Commented Jun 21, 2022 at 14:53
• from mathutils import Vector Commented Jun 21, 2022 at 14:53
• Thanks, you are the best. Commented Jun 21, 2022 at 14:57
• You can also scale the vector with a *= -1 or a = a * - 1. Please note in this case 0 can become -0 which is weird and can lead to problems if testing for equality. Commented Jun 21, 2022 at 15:33
• @Gorgious X and Y was asked to be inverted, not the Z Commented Jun 21, 2022 at 16:13