 # Create a Matrix

I’d like to create a matrix by appending numbers to it
In my case a 4x1 (4 rows, 1 column) matrix such as :

``````
&lt;Matrix 4x1 ( 0.5444)
(-0.8388)
(-0.0000)
(-1.0684)&gt;

``````

I’ve got the numbers but I don’t know how to create a matrix out of them.

I’m guessing the answer is somewhere in here :
https://docs.blender.org/api/249PythonDoc/Mathutils.Matrix-class.html

but can’t point my finger on it

Are you doing this for 2.49? If not, the current Blender docs are here:

https://docs.blender.org/api/current/

I don’t know about 2.49, but for 2.78 / 2.79 I think you have to use the Vector type instead of Matrix for a 4 x 1. The Matrix type can be multiplied by a Vector type though.

Example:

``````import bpy
from mathutils import Matrix, Vector

mat_bar = Matrix(( (1, 0, 0, -1), (0, 1, 0, -1), (0, 0, 1, -1), (0, 0, 0, 1) ))

vec_foo = Vector((0.5444, -0.8388, -0.0000, -1.0684))

mat_res = mat_bar * vec_foo

print(mat_res)

``````

I believe the mathutils Matrix type is limited to 2x2, 3x3, and 4x4 and the Vector type is limited to 1x2, 1x3, and 1x4. For anything more complex you would have to use the NumPy module (added sometime late in the 2.6x series).

Thank you, that’s what I was looking for.